Redo part of an already committed merge

后端 未结 3 794
小鲜肉
小鲜肉 2021-01-20 16:47

I have committed a big merge. Later, it appears that some files weren\'t merged correctly. I want to redo just these files, not the entire merge - the merge was big and I do

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-20 17:28

    If you have already pushed the branch after merging, and you suspect that someone else may have pulled it, then you should avoid editing the merge commit. Instead, you are safest just fixing the files and making a new commit with those changes.

    If this be not a concern, then you can try amending the merge commit, assumint that this merge commit is at the HEAD of your branch. Just edit the files which were merged wrongly, test your code, and if you are satisfied, then do an amended commit via:

    git commit --amend -m 'merge completed successfully'
    

    If you now inspect your commit history via git log, you will notice that the number of commits is the same as when you first completed the merge. But the latest commit is not the same as the first merge commit. Rather, it is a completely new commit with a new SHA-1 hash.

提交回复
热议问题