简体   繁体   English

Git拉合并获取

[英]Git pull merge fetch

I'm trying to solve a problem with Git. 我正在尝试解决Git的问题。 I'm using TortoiseGit. 我正在使用TortoiseGit。

Basically I checked out the master-branch and without making any changes and now I want to do an update of my local repo. 基本上,我签出了主分支,没有进行任何更改,现在我想更新本地存储库。

As I understand there a few commands for this: 据我了解,对此有一些命令:

Fetch : Downloads info from the remote branch 提取 :从远程分支下载信息

Merge : Merges said info into the local branch 合并 :将说的信息合并到本地分支

Pull : Combines above operations :结合以上操作

However, there a few things that I see that I don't understand: 但是,有些事情我看不明白:

  • When I do check for modifications, it shows me that I have modified a lot of files (which I didn't). 当我检查修改时,它表明我已经修改了很多文件(没有修改)。 I somehow think these changes are related to changes in the remote branch 我以某种方式认为这些更改与远程分支中的更改有关
  • When I do a fetch it fetches the remote info correctly, if I then do a merge it says "Already up to date", however, if I do a pull (which supposedly combines both) I get an error saying that my local modifications would be overwritten by the merge. 当我执行提取操作时,它会正确获取远程信息,如果执行合并操作,它会显示“已经更新”,但是,如果执行拉取(应该将两者合并),则会收到一条错误消息,提示我进行本地修改被合并覆盖。 This surprises me, since I didn't make any local modifications. 这让我感到惊讶,因为我没有进行任何本地修改。 This is probably related to the previous point, but I fail to see how. 这可能与上一点有关,但我看不出如何做。

Am I misunderstanding the basics of Git, or could anyone explain this behavior to me? 我是在误解Git的基础,还是有人可以向我解释这种行为?

There could be many things that can be considered a change. 可能有很多事情可以被认为是改变。 First of all the equivalent of git pull is actually. 首先,等效于git pull实际上是。

git fetch
git merge FETCH_HEAD

Now, after you do this, you probably want to do git diff FETCH_HEAD to see what is Git considering as a difference. 现在,执行git diff FETCH_HEAD此操作后,您可能想执行git diff FETCH_HEAD来查看Git考虑的区别。 You might want to replace FETCH_HEAD to something more user friendly, like origin/master . 您可能希望将FETCH_HEAD替换为更用户友好的名称,例如origin/master

It could be line-endings, or it could be simply the modification time of the files, either way, if you want to get rid of your "modifications", you can do git reset --hard which would reset all the work tree files to what they were in HEAD, and presumably you can do the pull now. 可能是行尾,也可能只是文件的修改时间,无论哪种方式,如果要摆脱“修改”,可以执行git reset --hard来重置所有工作树文件达到他们在HEAD中的状态,现在大概可以进行拉动了。

Alternatively, you can reset directly to the latest git reset --hard FETCH_HEAD (or eg origin/master). 或者,您可以直接重置为最新的git reset --hard FETCH_HEAD (或例如origin / master)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM