1

我有一个在本地运行的文件夹,其中包含一个网站。它非常愉快地在我的计算机上的 xampp 上运行。我知道过去已经与 git 挂钩,我继续通过命令行添加、提交和推送我的更改,这一切都像我所有其他 git 存储库一样工作,除了它们在我的 github 仪表板上在线更新以显示何时他们最后一次编辑等。

问题是这个文件夹 Demo 没有更新我的 github 仪表板上所谓的已连接存储库。我已经进行了大量更改,我正在将其提交给某个地方,但它不是我所期望的……它显示最多最近的变化是 4 个多月前!有什么方法可以轻松地重新连接两者吗?我不介意在 github 上显示的 ghost repo 中丢失任何东西,但我不能在本地 Demo 文件夹中丢失任何东西。我很高兴在 git 上做基础知识,但如果发生任何意外情况,我会感到害怕,我会删除所有内容!

4

1 回答 1

0

That message means that your local repo has diverged from the GitHub remote repo; that is, there are local commits that don't exist remotely, and vice versa.

If you really don't care what's happened to the remote repo, then you can run git push -f to force the push through, but if there are any other repos (yours or anyone else's) that have already pulled the non-local changes that have somehow ended up on GitHub, then this will really screw things up for them! Any changes on GitHub that you don't have locally will be lost.

If in doubt, commit any local changes, make a note of the current HEAD commit ID (you can use git show to find it) and then pull down the remote changes, fix any merge conflicts, and push back up. If things go wrong, you can always just git reset --hard <commit-id> to go back to where you were before. This route doesn't modify history, so there's no danger of losing anything.

Basically you need to be careful in Git with any operation that modifies the commit history of a repo, which push -f does, since it'll potentially lead to inconsistent histories between repos. On the other hand, if you only append to a repo's history (which is what you should be doing, e.g. with git commit, git pull, git merge, etc.) then if it breaks, you can always get it back into a working state just by rewinding to before the offending commits with git reset.


Also, you can see the commits on GitHub that you don't have with git log origin/master...master, or git diff origin/master...master to see the actual changes (make sure you run git fetch first).

于 2012-04-19T12:15:04.187 回答