1

My Mac had a hardware failure, so I transferred a git repository (a folder with all of the files including the .git file) to a Debian machine. From that Debian machine, I made a commit and pushed to origin/master (on Github) and made some uncommitted changes to files after that.

After repairing the Mac, I transferred this repo (including uncommitted changes) from Debian back to the Mac. Then I made a commit on the Mac. Git (via 'git status') is reporting that I am three commits ahead of origin/master. But if I compare the commit history on the Mac and on Github, I am actually only one commit ahead.

I'm afraid to do a push to origin/master without damaging something. Can I correct the local repo to being one commit ahead as it should be, or will a push fix itself?

4

1 回答 1

1

只需将本地分支master到临时分支并重置master本地状态:

git branch temporary master     # create a local branch called 'temporary' based on master
git checkout master             # checkout master if you haven't already
git fetch && git reset --hard origin/master    # reset it to origin

现在查看历史记录(你在master)并确保它是正确的。如果不是,并且临时分支是正确的:

git checkout -B master temporary    # reset master branch to temporary's state
于 2013-09-11T04:08:35.270 回答