Git,如何将origin / master重置为提交? [英] Git, How to reset origin/master to a commit?

查看:543
本文介绍了Git,如何将origin / master重置为提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  git reset --hard e3f1e37 

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

 #在分支主机上
#您的分支由7次提交支持'origin / master',并且可以快进。

#(使用git pull来更新你的本地分支)

没有提交,工作目录干净

因为我想重置origin / header,所以我签出origin / master:

  $ git checkout origin / master 
注意:检出'origin / master'。

您处于分离头部状态。你可以环顾四周,做一些实验性的
修改并提交它们,你可以放弃你在这个
状态下进行的任何提交,而不会影响任何分支,通过执行另一个结账。

如果要创建一个新分支以保留您创建的提交,则可以通过再次使用-b和checkout命令(现在或以后)来执行
。示例:

git checkout -b new_branch_name

HEAD现在处于2aef1de ... master问题已修复。它现在好了。

并通过此命令重置标题:

  $ git reset --hard e3f1e37 
HEAD现在在e3f1e37开发版本代码中增加了新版本。

然后我尝试添加对origin / header的提交,但我没有成功。

  $ git commit -m在e3f1e37恢复到项目的状态
#HEAD从原点/主点分离
没有提交,工作目录干净

最后,我将结帐给我的本地主人。

  $ git checkout master 
转换到分支master
您的分支由7次提交后的origin / master并且可以被快速转发。
(使用git pull来更新你的本地分支)

我希望本地和原产地应该在同一个方向,但正如你所看到的,git说我的本地/主人在7次提交后落后于原产地/主人。



我该如何解决这个问题?我正在寻找的东西是本地/主要和起源/主点指向相同的提交。以下图片显示了我所做的。感谢。



解决方案

你不能检查它们,因为它们不是指向你的本地存储库的指针(你只检查提交,这就是为什么你不会看到命令行界面分支标记中写的名字,只有提交哈希)。



您需要做的更新远程操作是强制将本地更改推送给master:

  git checkout master 
git reset --hard e3f1e37
git push --force origin master
#然后证明它(它不会打印任何diff)
git diff master..origin / master


I reset my local master to a commit by this command:

git reset --hard e3f1e37

when I enter $ git status command, terminal says:

# 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

Since I want to reset origin/header as well, I checkout to 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.

and reset the header by this command:

$ git reset --hard e3f1e37
HEAD is now at e3f1e37 development version code incremented for new build.

Then I tried to add commit to origin/header that I was not successful.

$ git commit -m "Reverting to the state of the project at e3f1e37"
# HEAD detached from origin/master
nothing to commit, working directory clean

Finally, I checkout to my local master.

$ 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)

Since, I reset the head of origin/master I expect local and origin should be in same direction but as you see, git is saying that my local/master is behind origin/master by 7 commits.

How can I fix this issue? The things that I'm looking for is Head of local/master and origin/master point to same commit. Following image shows what I did. Thanks.

解决方案

origin/xxx branches are always pointer to a remote. You cannot check them out as they're not pointer to your local repository (you only checkout the commit. That's why you won't see the name written in the command line interface branch marker, only the commit hash).

What you need to do to update the remote is to force push your local changes to master:

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,如何将origin / master重置为提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆