Question

I've done some commits at my repository that I want to remove. I've come back to the commit which I want to preserve:

$ git checkout commit_hash_num

How should I proceed to remove the next commits?

Was it helpful?

Solution

just

git reset --hard commit_hash_num

Fair Warning:

  • this does really modify your branch's HEAD to refer to the old commit
  • this loses any local, uncommitted changes

Don't worry too much, though: you can always immediately go back:

git reset --hard HEAD@{1}

in case you get second thoughts with respect to those later commits. Or, maybe:

git checkout -v save_wrong_commits_branch HEAD@{1}

to get back the dropped commits on a spearate branch with an apt name :/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top