문제

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