-1

I have like 20 commits and I need to remove one of the commits (commit #20). I have tried:

git reset --hard hashID

but it is moving the head to that particular head:

HEAD is now at someID

I don't want to change the head I just want to remove those changes.

What can I do? How can I remove that particular commit and keep the rest of the commits?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
user2924482
  • 8,380
  • 23
  • 89
  • 173
  • 1
    Possible duplicate of [How to remove specific commits from GIt?](https://stackoverflow.com/questions/46724078/how-to-remove-specific-commits-from-git) – mkrieger1 May 20 '19 at 19:45

1 Answers1

1

If you don't mind rewriting the history of the branch:

git checkout hashID~1 # stand on the previous revision
git cherry-pick hashID..the-branch # replay all revisions after the one I want to remove
# if you like the results
git branch -f the-branch
eftshift0
  • 26,375
  • 3
  • 36
  • 60
  • how I'll do if I want to keep the history ? – user2924482 May 20 '19 at 19:43
  • If you want to keep that revision in history, then what you are asking for is `git revert hashID` which will revert the changes introduced on that revision at the tip of your current branch. – eftshift0 May 20 '19 at 19:50