Git,如何将原点/主机重置为提交?
我重置我的本地主人到这个命令的提交:
git reset --hard e3f1e37
当我input$ git status
命令时,terminal说:
# On branch master # Your branch is behind 'origin/master' by 7 commits, and can be fast-forwarded. # (use "git pull" to update your local branch) # nothing to commit, working directory clean
因为我想重置origin / header,所以我签出origin / master:
$ git checkout origin/master Note: checking out 'origin/master'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b new_branch_name HEAD is now at 2aef1de... master problem fixed for master. its okay now.
并通过此命令重置标题:
$ git reset --hard e3f1e37 HEAD is now at e3f1e37 development version code incremented for new build.
然后我试图添加提交到origin / header,我没有成功。
$ git commit -m "Reverting to the state of the project at e3f1e37" # HEAD detached from origin/master nothing to commit, working directory clean
最后,我向当地的主人结帐。
$ git checkout master Switched to branch 'master' Your branch is behind 'origin/master' by 7 commits, and can be fast-forwarded. (use "git pull" to update your local branch)
因为,我重置了原产地/主人的头我希望本地和原产地应该在同一个方向,但正如你所看到的,git是说我的本地/主人在7个提交背后的起源/主人。
我该如何解决这个问题? 我正在寻找的东西是本地/主和头/主指向相同的提交。 以下图片显示了我所做的。 谢谢。
origin/xxx
分支始终是指向远程的指针。 你不能检查它们,因为它们不是指向你的本地仓库的指针(你只是签出提交,这就是为什么你不会看到写在命令行界面分支标记中的名字,只有提交哈希)。
你需要做什么来更新远程是强制推动您的本地更改为主:
git checkout master git reset --hard e3f1e37 git push --force origin master # Then to prove it (it won't print any diff) git diff master..origin/master
在这里find的解决scheme帮助我们将主更新到之前已经被推送的提交:
git checkout master git reset --hard e3f1e37 git push --force origin e3f1e37:master
与接受的答案的主要区别在于push命令中master之前的提交散列“e3f1e37:”。