Git:如何在Mercurial中更新像hg-C这样的工作目录 [英] Git: how to update the working directory like hg up -C in Mercurial

查看:103
本文介绍了Git:如何在Mercurial中更新像hg-C这样的工作目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前曾与mercurial合作,但现在已经与git合作。有一些问题,因为git仍然有点不同。



你能否建议如何将git存储库更新为最后一次提交,放弃所有更改和冲突,因为它在Mercurial中执行 hg up -C



我被建议命令 git checkout


你的分支和'origin / master'已经分开了,并且有分别为24和5个不同的提交。

应用此命令后,工作目录中的文件不会更新。

解决方案

首先,您收到的错误消息是告诉您分支的本地和远程版本已经发生分歧。为了从远程分支获得更改,您必须进行合并或重新分配。假设你想使用合并策略,你可以试试这个:

  git fetch#从远程$ b获取最新的变化$ b git checkout theBranch#结帐你的本地分支
git合并-X他们的原产地/ theBranch#与远程分支版本合并



-X他们的选项在 git merge 意味着你将无条件地保留来自远程的文件的版本,覆盖您可能在本地的任何版本。



由于这篇SO文章讨论了,如果合并导致本地文件被删除,那么你可能不得不手动删除它使用:

  git rm / path / to / deleted / file 

然后,您可以进行合并提交并继续工作。


I previously worked with the mercurial, but now with git. there were some problems, because git still a little different.

Could you suggest how you can update the git repository to the last commit, discarding all changes and conflicts, as it does for example hg up -C in Mercurial

I was advised to command git checkout -f, it displays this message:

Your branch and 'origin/master' have diverged, and have 24 and 5 different commit(s) each, respectively.

After applying this command, the files in the working directory are not updated.

解决方案

First, the error message you are getting is telling you that the local and remote versions of your branch have diverged. In order to get the changes from the remote branch you will either have to merge or rebase. Assuming you want to use a merge strategy, you can try this:

git fetch                             # get the latest changes from the remote
git checkout theBranch                # checkout your local branch
git merge -X theirs origin/theBranch  # merge with remote version of the branch

The -X theirs option in the git merge means that you will unconditionally keep the version of the files coming from the remote, overwriting whatever version you might have locally.

As this SO article discusses, if the merge results in a local file being deleted, then you may have to manually remove it using:

git rm /path/to/deleted/file

Then you can make your merge commit, and continue working.

这篇关于Git:如何在Mercurial中更新像hg-C这样的工作目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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