重置本地存储库分支就像远程仓库HEAD [英] Reset local repository branch to be just like remote repository HEAD

查看:112
本文介绍了重置本地存储库分支就像远程仓库HEAD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我做过:

  git reset --hard HEAD 

但是当我运行了一个 git status

 分支主
要提交的更改:
(使用git reset HEAD< file> ...停用)
修改:java / com / mycompany / TestContacts.java
修改:java / com /mycompany/TestParser.java

你能告诉我为什么我要这些'修改'吗?我没有触及这些文件?如果我这样做了,我想删除它们。

解决方案

设置分支以完全匹配远程分支可以分两步完成:

  git fetch origin 
git reset --hard origin / master

如果您想在执行此操作前保存当前分支的状态(以防万一),您可以这样做:
$ b $ b

  git commit -a -m保存我的工作,以防万一
git branch my-saved-work

现在你的工作被保存在分支my-saved-work中,以防你决定返回它(或者想看看它)请注意,第一个例子假设远程仓库的名称是origin,而在第二个仓库中名为master的分支远程回购与当地回购协议中的当前签出分支相匹配。



顺便说一句,你所处的这种情况看起来非常像一个常见情况,是完成到非裸仓库的当前签出分支。你最近推入了你的本地回购?如果没有,那么不用担心 - 其他的东西一定会导致这些文件意外地被修改。否则,您应该意识到,不建议将其推入非裸仓库(特别是不要进入当前检出的分支)。


How do I reset my local branch to be just like the branch on the remote repository?

I did:

git reset --hard HEAD

But when I run a git status,

On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)
      modified:   java/com/mycompany/TestContacts.java
      modified:   java/com/mycompany/TestParser.java

Can you please tell me why I have these 'modified'? I haven't touched these files? If I did, I want to remove those.

解决方案

Setting your branch to exactly match the remote branch can be done in two steps:

git fetch origin
git reset --hard origin/master

If you want to save your current branch's state before doing this (just in case), you can do:

git commit -a -m "Saving my work, just in case"
git branch my-saved-work

Now your work is saved on the branch "my-saved-work" in case you decide you want it back (or want to look at it later or diff it against your updated branch).

Note that the first example assumes that the remote repo's name is "origin" and that the branch named "master" in the remote repo matches the currently checked-out branch in your local repo.

BTW, this situation that you're in looks an awful lot like a common case where a push has been done into the currently checked out branch of a non-bare repository. Did you recently push into your local repo? If not, then no worries -- something else must have caused these files to unexpectedly end up modified. Otherwise, you should be aware that it's not recommended to push into a non-bare repository (and not into the currently checked-out branch, in particular).

这篇关于重置本地存储库分支就像远程仓库HEAD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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