1

I've recently started using Git. I've run into a bit of a problem. I was working on something, that I committed, but when I went to push the commits I got a merge conflict. I pressed some stuff and somehow, the git repository has my commit as the head, and the work that was pushed right before mine was not merged (due to the conflict).

Could somebody please point me in the right direction?

I'm assuming that I need to somehow pull the previous commit (that was not merged), merge it with mine, and then push both back up.

I also realised that to deal with the merge conflicts I can use a tool like meld. Again, I'm quite new to this.

Thanks.

Jean-Luc
  • 3,254
  • 7
  • 35
  • 71
  • "I pressed some stuff"? Did you do a `git push --force`? Otherwise, regarding merge conflicts, see http://stackoverflow.com/a/7589612/6309 – VonC Mar 19 '13 at 09:05
  • No. I think what's happened is, the files added be the person in the previous commit added to mine; however, any changes to code files i pushed made in the previous commit were not reflected in my push. – Jean-Luc Mar 19 '13 at 09:07
  • So you basically erased that previous version with your commit made on top of it, which you then pushed, right? – VonC Mar 19 '13 at 09:09
  • In that case, you cannot merge back that old version with a `git merge`, as it would consider that old commit already part of the history of the destination commit. Let me check what other options exist. – VonC Mar 19 '13 at 09:14
  • Did the "`git checkout --merge`" worked? Or did you do a manual merge? – VonC Mar 19 '13 at 09:57
  • I was worried about messing it up more; I don't fully know what I'm doing, so I just manually downloaded and merged the file using Meld (I hadn't even used Meld before but it was pretty straight forward). Thank you for the answer though. If I may ask (to see if I understand correctly), basically, git checkout master~2 will pull the revision (2 revisions ago) and store it locally on my computer, then git checkout --merge will grab that revision and merge it? Mind you, I'm pretty sure that would've caused a merge conflict like in the first place. – Jean-Luc Mar 19 '13 at 10:01
  • 1
    the last checkout would try to restore the *current* version (HEAD), but will see that the index has a different content than HEAD (namely the one in master~2, for instance): a merge should ensue. – VonC Mar 19 '13 at 10:03

1 Answers1

1

You can try:

# restore the old version of that file
# supposing it was 2 revisions ago on master branch
git checkout master~2 -- path/to/your/file

# merge it with the most recent version
git checkout --merge -- path/to/your/file

If it doesn't work, then you need to restore that old file elsewhere, and manually merge it to your current revision for that file, adding and committing a new version (which, this time, won't simply overwrite the old version).

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283