views:

35

answers:

2

Hello, I'm using git with my friend. I did a few commits and my friend didn't update his local repo and pushed with -f arugment:

git push -f origin master

Now in the git server (github) my commits are destroyed and the latest commit is my friends. But I have a history of commits locally. Can I somehow merge them back to the master? Or I have to do it by hands with newest version?

+3  A: 

Seems like your friend did change something already published on a public repository. See http://progit.org/book/ch3-6.html. Start by burning your friend.

Normally a git pull should trigger a merge on your side. You can always copy your whole repository as backup in case. Also you can simply copy the changes from your latest version to a new checkout and commit all of them as a single commit.

Wernight
A: 

I haven't tested this, but I think I'd do force your commits to be published to github (thus re-writing the history again), have your "friend" pull your changes, rebase his changes, then push his changes up. This way, you get both your changes to the same place.

A good rule of thumb is to NEVER FORCE A COMMIT TO GITHUB :) Do it this once to get your repo back to the state it was in before your "friend" messed it up:

# on your machine
git push origin master --force

#now your "friend's" working copy is fairy screwed up, so on his machine:
git checkout -b screwed_up #checks out a new branch called screwed_up
git pull origin master # pulls in your changes
git checkout master #checks out his version with his changes
git rebase screwed_up #moves his changes to the end of your changes (see git graphs for more details)
git commit -am 'your message here'
git push origin master #pushes his changes, which are now merged with your changes back to github
Bryce