2

I'm not too familiar with Git terms so please use more common terms with explanation. I'm using Github Desktop, which I have already commit into my branch. Now I want to open pull request to master, but before I do that, I use the option "update from Master" first to get all the changes from the master, so that when I do the pull and merge, I will not get any conflicts on the master.

When I do update from Master, I got some conflicts. As usual, I go and resolve that conflict. But then I realised that I resolve the conflicts incorrectly, and I want to "reset" the state of files like the beginning of the conflicts so I can do over. I don't know what to do at this point.

  • I have tried to git stash all the changes so I can "update from Master" again, but the git stash failed. And git stash never failed before on me. (fatal: git-write-tree: error building trees Cannot save the current index state).
  • I have tried to git reset but it seems nothing resetting. And what I know is git reset is actually undoing my latest commit so I'm afraid my commit now messing up with the updated and uncommitted code from the master.

What I'm supposed to do to "reset" the state of files like the beginning of conflicts so I can do conflict resolve over? Thanks.

Chen Li Yong
  • 5,459
  • 8
  • 58
  • 124
  • I use sourcetree application so with UI is more easily. – Luca C. May 30 '17 at 04:26
  • refer : https://git-scm.com/book/en/v2/Git-Branching-Rebasing – Gahan May 30 '17 at 04:28
  • @LucaC. I also use sourcetree. But at this time, I also don't know what to do at sourcetree to fix this mess. I usually use github desktop because it's more simple and gets the job done. And use the sourcetree if I need to do some problem solving, like this one. But this is way too messy to be fixed. – Chen Li Yong May 30 '17 at 04:29
  • @Gahan okay from your link, now I know that I use the wrong term. It's not rebasing, but merging. So I will change the title. – Chen Li Yong May 30 '17 at 04:29
  • 1
    in [merging](https://git-scm.com/docs/git-merge) you have to solve conflict by your self. to solve the conflicts in fill you can use tool such as [winmerge](http://winmerge.org/?lang=en) or use and online site such as [diffchecker](https://www.diffchecker.com/).. go through this [link](http://ohshitgit.com/) for any trouble – Gahan May 30 '17 at 04:32
  • @Gahan I find that links very useful. Thanks. And btw, I found the answer to undo everything: `git stash -u`. https://stackoverflow.com/questions/22620393/various-ways-to-remove-local-git-changes – Chen Li Yong May 30 '17 at 04:39

1 Answers1

2

If merge was wrong you can perform this steps:

  • git reset HEAD~1
  • git add .
  • git reset --hard

This will remove latest commit. Now you can re do the merge.

But I also suggest another solution to solve merge conflicts: rebase. With rebase you need to move in you feature branch and run a command like git rebase -i master. If there are no conflict it will be like your branch started from the latest master: like if your master will be up-to-date. A rebase move all commits, so when a rebase meets conflicts, the rebase is "paused" and you are invited to solve each conflict. If you follow the rebase instructions, for each commit with conflicts you need to fix the commit by hand, git add and then git rebase --continue (but just follow the command instructions).

sensorario
  • 20,262
  • 30
  • 97
  • 159
  • Oh wow, I never know about this kind of way to use rebase. Thanks! Btw, I have already solved my issue with `git stash -u` (even though I don't know what `-u` means), but your answer also answer my question why my `git reset` wasn't working. – Chen Li Yong May 30 '17 at 06:28