Delete the second last commit

Delete the second last commit

Let's say the bad commit dd61ab32 is not the top commit, but a slightly older one, e.g. the second last one. We want to remove it, but keep all commits that followed it. In other words, we want to rewrite the history and force the result back to mathnet/master. The easiest way to rewrite history is to do an interactive rebase down to the parent of the offending commit:
1: 
$ git rebase -i dd61ab32^
This will open an editor and show a list of all commits since the commit we want to get rid of:
1: 
2: 
3: 
pick dd61ab32
pick dsadhj278
...
Simply remove the line with the offending commit, likely that will be the first line (vi: delete current line = dd). Save and close the editor (vi: press :wq and return). Resolve any conflicts if there are any, and your local branch should be fixed. Force it to the remote and you're done:

1: 
$ git push mathnet -f

Comments

Popular posts from this blog

Login/Logout account Git in Terminal/cmd

Logout Git on MacOS

React Tutorial for Beginners