为什么从特定的GitHub存储库合并到本地Git存储库会导致本地存储库中未提交的更改? [英] Why does merging from a particular GitHub repository into a local Git repository result in uncommitted changes in the local repository?

查看:119
本文介绍了为什么从特定的GitHub存储库合并到本地Git存储库会导致本地存储库中未提交的更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个GitHub存储库,我们称它们为 GH1 GH2 ,还有2个相应的本地存储库,我们称它们为 LR1 LR2 ,将它们作为遥控器.为了清楚起见,这是本地存储库到远程存储库的映射:
LR1 ---> GH1
LR2 ---> GH2

I have 2 GitHub repos, let's call them GH1 and GH2, and 2 corresponding local repos, let's call them LR1 and LR2 that have them as remotes. For clarity, here is the local repo to remote repo mapping:
LR1 ---> GH1
LR2 ---> GH2

我使用GitHub Web UI手动将同一文件(称为 A.jpg )上传(并提交)到两个GitHub存储库中. 当我尝试从遥控器合并回本地存储库时,会得到不同的结果.

I manually upload (and commit) the same file, let's call it A.jpg, to both GitHub repos using the GitHub web UI. I get different results when I try to merge from the remotes back down to my local repos.

出于此问题,我在命令行上使用git.

I use git on the command line for the purposes of this problem.

一个本地存储库( LR1 )的行为与我期望的一样: git fetch从远程获取更改,但不合并. git merge合并 A.jpg 并快速转发本地存储库. git status显示没有任何内容可进行,工作目录清除"

One of local repos (LR1) behaves as I would expect: git fetch gets the change from the remote but doesn't merge it. git merge merges A.jpg and fast-forwards the local repo. git status shows that there is "nothing to commit, working directory clean"

另一个( LR2 )的行为与我期望的不同: git fetch从远程获取更改,但不合并. git merge合并 A.jpg 并快速转发本地存储库. git status显示 A.jpg 被修改,并且是未提交的更改.

The other one (LR2) behaves differently than I would expect: git fetch gets the change from the remote but doesn't merge it. git merge merges A.jpg and fast-forwards the local repo. git status shows that A.jpg is modified and is an uncommitted change.

git pull的行为方式相同,但是为了解决此问题,我认为我会明确调用2个执行此命令的命令(git fetchgit merge)就像拉一样.

git pull behaves the same way, with respect to the 2 local repos, but for the purposes of breaking this problem down, I thought I would explicitly call out the 2 commands (git fetch and git merge) that do the same thing as a pull.

我假设我以不同的方式配置了2个本地git存储库,这就是造成此问题的原因. 什么会导致这种行为?

I assume that I have the 2 local git repos configured differently and that is causing the issue. What would cause this behaviour?

推荐答案

感谢这篇文章的有用评论,我将分享我对该问题的理解以及如何解决这个问题.

I'll share my understanding of the problem and how I resolved this, thanks to the helpful comments on this post.

问题与SMB挂载,文件权限和git配置有关.问题是,当我使用git从远程同步到本地存储库并且git需要在本地存储库中创建新文件时,git使用其权限的默认设置(644)和SMB创建了一个新文件.本地存储所在的mount尚未为文件模式配置任何设置,因此使用的是默认设置(755).最终结果是git认为它正在创建一个具有644权限的文件,但是一旦创建,它就假定了755权限,因为这是新文件的装载力……所以git认为刚创建的文件已更改,将其视为未提交的本地更改文件.通过一些更改解决了该问题:

The problem has everything to do with the SMB mount, file permissions, and git configuration. The problem is that when I use git to sync from the remote to my local repo and a new file needs to be created by git in my local repo, git is creating a new file using its default setting for permissions (644) and the SMB mount, under which the local repo existed, has no setting configured for file mode so it was using its default (755). The end result was that git thought it was creating a file with 644 permissions but as soon it got created it assumed 755 permissions because that's what the mount forces for new files...and so git thought that the file it just created had changed and deemed it as an uncommitted locally changed file. This was resolved by a few changes:

  • 更改了/etc/fstab中的SMB挂载以包括文件模式 (file_mode=0644)符合git的需求
  • 执行完此操作并卸载/重新安装它之后,我中的所有文件 本地回购现在显示为未提交的本地更改,因为 权限(644)与我的本地仓库知道的不同,并且 我的git设置对此很敏感.我通过检查 git设置
  • Changed the SMB mount in /etc/fstab to include the file mode (file_mode=0644) that matches what git wants
  • Once I did this and unmounted/remounted it, all of the files in my local repo now show as uncommitted local changes because the permission (644) is different than what my local repo is aware of and my git settings are sensitive to that. I verified it by checking the git settings

git config --get core.fileMode

  • 此问题已通过更改git的配置来解决 资料库.在本地存储库根目录的.git文件夹中,我编辑了 配置文件,以便filemode = false.
  • 完成此操作后,git status显示没有未提交的本地 变化.
  • This was resolved by changing the git configuration for the repository. In the .git folder in the local repo root, I edited the config file so that filemode = false.
  • Once I did this, git status shows that there are no uncommitted local changes.

此git 文档很好地解释了怎么发生的,这与我所经历的非常接近(即,在将远程回购复制到SMB挂载之前将其复制到本地磁盘上的本地回购中,然后最终将本地回购转移到SMB挂载中)

This git documentation explains well how this could happen, which is very close to what happened to me (i.e. cloned remote repo to local repo on local disk before it was on SMB mount and then eventually moved the local repo to an SMB mount)

现在,将新文件添加到GitHub存储库中,然后下拉至本地存储库,不再显示为本地未提交的更改.而是将它们正确,透明地合并.

Now, new files added to the GitHub repo and then pulled down to the local repo no longer show up as locally uncommited changes. Rather, they are merged properly and transparently.

这篇关于为什么从特定的GitHub存储库合并到本地Git存储库会导致本地存储库中未提交的更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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