GIT: remove commit halfway down in log but keep all overs

120 views Asked by At

Hi I have a commit in my git repo which I want to remove, but I want to keep all other commit thereafter.

df5bf4b != 'Test' to =='Test'
c1f6f9f fixed occupations getJob to check if is empty
4e818fa added utility links partial to client template. Remove old utility links
f954acf Changes 'Site Map' link
276cd1f resolve conflict
db65577 Changes link
57f776e Changes corporate header 'Insights' link and underlines 'E-Briefings'
9f96c8f Changes link in the cookie banner for corporate sites
5b3d187 Moves 'Client' validation messages to JS alert box

I want to remove commit 9f96c8f but keep every commit below and above, is there a way I can do this??

Thanks in advance.

2

There are 2 answers

0
Tony Barnes On BEST ANSWER

You can do a git rebase:

$ git rebase -i HEAD~8

This will launch your editor, and you can pick the commits you want.

0
David Deutsch On

If you have already pushed the commit to the central repository, and other people also use this repository, then you really can't "remove" the commit (at least without coordinating with all the other developers and having them run certain commands on their local machines). If you simply want to undo the changes introduced in that commit, you should do a revert: git revert 9f96c8f. This will not remove the commit from the history, but the end state of the working directory will be as if the commit never happened.

If on the other hand you have not pushed the offending commit to the repository, then you can do a rebase as described in Tony Barnes' answer.