質問

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?

役に立ちましたか?

解決

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 :/

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top