Git,如何将origin / master重置为提交?

我将本地主设备重置为通过此命令提交:

git reset --hard e3f1e37

当我输入$ git status命令时,终端会说:

# 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

这里找到的解决方案帮助我们将主更新为之前已经推出的提交:

git checkout master
git reset --hard e3f1e37
git push --force origin e3f1e37:master

与接受的答案的主要区别在于push命令中master之前的提交散列“e3f1e37:”。

链接地址: http://www.djcxy.com/p/23605.html

上一篇: Git, How to reset origin/master to a commit?

下一篇: Git update submodule recursive