0

Me and a friend are working on a small project hosted on Github. Neither of us are very experienced (clearly).

I submitted a pull request that was successfully merged however, my friend did not update his local repository to include these latest changes.

When my friend next did a push, he overwrote all of my changes.

How can I retain most (excluding conflicts) of my edits and his?

I tried making a branch based on my last commit, and then merging said branch with the master branch however doing so did not work because because the master branch was said to be "up to date" and now I am lost.

Caster Troy
  • 2,796
  • 2
  • 25
  • 45
  • This might help http://stackoverflow.com/questions/4114095/revert-to-previous-git-commit – Jim Jun 04 '14 at 19:05
  • 1
    The only way to overwrite data when pushing is using `--force`. If there's any problem while pushing, NEVER resort to that parameter, unless you really know what you are doing. – KurzedMetal Jun 04 '14 at 19:06
  • @Jim If I revert to my last commit all of his code will be lost no? How should I proceed after returning to my commit? Thanks. – Caster Troy Jun 04 '14 at 19:07
  • @KurzedMetal Thanks for the advice Kurzed. I think my friend just searched around until he found a command that "worked". We are mostly working on this project to get experience with working as a team using Git. – Caster Troy Jun 04 '14 at 19:07
  • @CasterTroy He should have his code locally still? If you revert and he should be able to pull and merge with his current files... I think, I haven't used git in a while, but if he has his code locally, worst case scenario revert, get him to back his up and pull and go from there? – Jim Jun 04 '14 at 19:13

1 Answers1

1

The best way to resolve this issue would be to do a fetch followed by a merge or a rebase. I would suggest a rebase to keep your history linear and clean.

fetch updates your copy of the remote branch while not touching your own branch. A git pull will effectively do a fetch followed by a merge.

The command chain to resolve your problem would look like this

git fetch
git rebase origin/master master
# ... Solve conflicts ... (continue the rebase with 'git rebase --continue')
git push

If your friend commited during the time you were resolving the conflicts you should do a git pull --rebase before pushing. But git will tell you about this, when you try to push, so I wouldn't worry about it until it screams at you.

Sascha Wolf
  • 18,810
  • 4
  • 51
  • 73