0

I have merged two branches, and have commited it. However, I found that I made mistakes in some files while resolving the conflicts.

commit 1234567
Merge: abcdefg hijklmn
Date: ....

    Merge branch 'master' of repo into branchA

    Conflicts:
        fileA
        ...

I'd like to roll back some files to the unresolved state, and resolve the conflicts again. How can I do this?

Thank you in advance.

Han
  • 625
  • 2
  • 7
  • 25

2 Answers2

1

Use git reset 'commit_id' --hard to reset your current branch one commit before the merge commit. Then merge the branch again and commit.

If you want to change single file only, assuming the merge commit you want is abcde: git checkout abcde~1 'path/to/file'. To restore file to state before that commit. Then just merge again. Cited from: https://stackoverflow.com/a/215731/1712948

Community
  • 1
  • 1
mcs_dodo
  • 738
  • 1
  • 10
  • 17
  • Can I do this only on some specific file? What should I do after "git reset abcdefg fileA"? – Han Jun 16 '16 at 13:29
  • Thank you for your help. What should I do after checking it out? Can I merge it with commit "hijklmn"? – Han Jun 16 '16 at 14:18
  • I merged it with "git checkout -p -- " but I'd like to know a better way. – Han Jun 16 '16 at 15:56
0

Well if you have already pushed out the change then that is an issue. There are two options ,

1.Add more commits and correct the errors that you made. Make sure the commit message explains why you are doing that. This will make sure history is maintained correctly.

2.The second option deals with messing up the history. So if you decide to do this remember you are going to mess up history so you have to risk it ! This is not a standard practice and highly discouraged. Do a gitk on the branch you expect to fix. Click on the commit where you want to reset the branch to. Right click and select reset branch to here. Now do the merge correctly. Force push the branch upto the repo.

Now if you have not pushed out the changes then it becomes simpler. Just reset your local feature branch to where you want it to be. Redo the merge. Rebase against the master and push it out.

rubenvb
  • 74,642
  • 33
  • 187
  • 332
Som Bhattacharyya
  • 3,972
  • 35
  • 54
  • Unfortunately, I have already pushed it. I don't mind adding more commits and leaving history but I don't know how to exactly do it. I think I can checkout the file to previous commit but I'm not sure. I would like to do this only on some specific files. – Han Jun 16 '16 at 13:22