Git:拉取和合并问题

huangapple go评论66阅读模式
英文:

Git: Pull and Merge Questions

问题

Q1:
如果我决定进入我的本地项目并执行Pull,子模块3在我的本地仓库会被更新为远程仓库上的信息吗?换句话说,它会覆盖我的本地仓库中的任何信息吗?

Q2:
如果子模块3,假设有五个文件,并且与我的本地仓库保持最新状态。然后,队友在远程仓库中删除了两个文件,只留下三个文件在远程仓库中。

如果我然后进入我的本地仓库并执行Pull,那么本地多余的文件会被删除,以使其与远程仓库保持最新,总共只有三个文件吗?

英文:

I'm following Git tutorials but I'm still not very clear about the Pull command and the effects on the remote and local repositories.

My two questions are the following:

Q1:
Let's say I have a project with submodules 1 2 and 3, the local and remote repos are up to date. Now, a teammate changes submodule 3 on the remote repo.
So now, the remote will be ahead by one commit.

  • If I decide to go into my local project and Pull.
    Will submodule 3 on my local repo be updated with the information that is on the repo?
    In other words, will it overwrite whatever is on my local repo with that information?

Q2:

  • If submodule 3, let's say has five files, and is is up to date with my local repo.
    And teammate deletes two files in the remote, leaving only three files on the remote repository.

If I then go into my local repo and Pull, will extra files on local be deleted so that it is up to date with what's on the remote, leaving a total of just three files?

Thanks

答案1

得分: 1

是的,是的。
即使包括一些文件删除,您也将获得最新的更新。
对于Git来说,这是可能的“修改”之一,可以应用于文件,并且Git可以跟踪。

英文:

Yes and Yes.
You will have have the latest update even if that includes some file deletion..
For Git, that’s one of the possible “modifications” that could be applied to a file, and that Git could track.

答案2

得分: 1

It will update but not necessarily overwrite the content in your submodule 3 directory. If you have no local modifications, yes then git pull will update all files updated remotely. If you should have any files modified you will get a conflict (can be mitigated with git pull origin --rebase). In other words there is nothing special with this submodule repository, git pull behaves the same as everywhere.

Where there is a difference though is that after you do a pull inside the submodule it will be marked as updated and dirty in the parent repository but it will not make any changes to the version it is linked to. To do that you need to explicitly from the parent repo do git add submodule3dir; git commit -m "Updated submodule 3 to latest version".

In other words git pull inside a submodule will update your worktree, but it will not update your index and it will not create a corresponding commit. You need to explicitly run add and commit to do that.

英文:

> will it overwrite whatever is on my local repo with that information?

It will update but not necessarily overwrite the content in your submodule 3 directory. If you have no local modifications, yes then git pull will update all files updated remotely. If you should have any files modified you will get a conflict (can be mitigated with git pull origin --rebase). In other words there is nothing special with this submodule repository, git pull behaves the same as everywhere.

Where there is a difference though is that after you do a pull inside the submodule it will be marked as updated and dirty in the parent repository but it will not make any changes to the version it is linked to. To do that you need to explicitly from the parent repo do git add submodule3dir; git commit -m "Updated submodule 3 to latest version".

In other words git pull inside a submodule will update your worktree, but it will not update your index and it will not create a corresponding commit. You need to explicitly run add and commit to do that.

huangapple
  • 本文由 发表于 2023年4月17日 10:57:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76031429.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定