开发者

A little git trouble

开发者 https://www.devze.com 2023-01-20 18:31 出处:网络
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 arugmen开发者_如何转开发t:

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 arugmen开发者_如何转开发t:

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?


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.


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


Pushing back your own local commit is one way (git push origin master --force), but it erases your friend's contribution.

You could:

  • rename master on GitHub (see "renaming remote git branch")
  • fetch that "friend_master" branch from GitHub, and rebase it on top of your master, integrating your friend's contributions, and validating them.
  • git push origin master (recreating master branch with a full content)

Then your friend can simply reset his/her local master branch to origin/master.

0

精彩评论

暂无评论...
验证码 换一张
取 消