Git undo auto merging on a specific file only, not the whole branch

后端 未结 3 1181
醉梦人生
醉梦人生 2021-02-18 18:04

Is there a way I can undo a auto-merge of one file that has been changed instead of the whole branch in Git?

I want to undo this merge:

Auto-mergi

3条回答
  •  遇见更好的自我
    2021-02-18 18:43

    When you do:

    git reset HEAD~1 public/stylesheet/application.css
    

    ... that changes the version of your file in the index (i.e. the staged version) to the version in HEAD~1 - your working copy remains the same. The current documentation explains this as:

    This form resets the index entries for all to their state at

    If you do:

    git checkout HEAD~1 -- public/stylesheet/application.css
    

    ... that will change both the working copy and the staged version to the version from HEAD~1. The -- is there for safety, just in case you have file name that can also be understood as a commit.

    Now that you're got that change staged, you could amend the merge commit with:

    git commit --amend
    

    ... which is fair enough as long has you haven't pushed the merge anywhere, since the merge will still just have changes from one branch or the other.

提交回复
热议问题