Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (29.3k points)

In one of my development branches, I made some changes to my codebase. Before I was able to complete the features I was working on, I had to switch my current branch to master to demo some features. But just using a "git checkout master" preserved the changes I also made in my development branch, thus breaking some of the functionality in master. So what I did was commit the changes on my development branch with a commit message "temporary commit" and then checkout master for the demo.

Now that I'm done with the demo and back to work on my development branch, I would like to remove the "temporary commit" that I made while still preserving the changes I made. Is this possible?

1 Answer

0 votes
by (50.2k points)

git reset --soft HEAD~1

And this will delete the recent commit and it doesn’t do anything to your work.


Or there is a way you can use without using --soft option


git reset HEAD^

Which moves your HEAD to point to the specified commit, without changing any files

And HEAD^ refers to the parent commit of your current commit.

Browse Categories