简体   繁体   English

Git认为在切换分支时未跟踪文件

[英]Git believes tracked files are untracked when switching branches

From master branch, create a new branch and push to remote 在主分支中,创建一个新分支并推送到远程

git checkout -b not_master (example second branch)
git checkout not_master
git push origin not_master

Now my local working copy is on the not_master branch. 现在,我的本地工作副本位于not_master分支上。

I've renamed all files where the first character of the file name is in lowercase to uppercase. 我已将文件名的第一个字符小写改为大写的所有文件重命名。

I noticed git did not record the case changes so I updated my config using 我注意到git没有记录大小写更改,因此我使用

git config core.ignorecase false 

I then committed and pushed the changes to not_master 然后,我提交并将更改推送到not_master

Here's where the issue arises, when attempting to switch back to master git informs me that there are untracked files present and those untracked files will be overwritten by checkout, the untracked files are all of the files where I changed the filename. 这就是问题所在,当尝试切换回master git时,通知我存在未跟踪的文件,并且这些未跟踪的文件将被签出覆盖,这些未跟踪的文件是我更改了文件名的所有文件。

How can I keep two branches with the same files that only differ in filename? 如何使用相同的文件(仅文件名不同)保留两个分支?

If I checkout master using the f flag then all files that have been renamed will be deleted in master. 如果我使用f标志签出master,则所有已重命名的文件都将在master中删除。

Is this expected behavior? 这是预期的行为吗?

You should use git mv <oldfilename> <newfilename> for each file 您应该为每个文件使用git mv <oldfilename> <newfilename>

The config option core.ignorecase is false by default and only adds optimizations for filesystems that don't support case-sensitivity. config选项core.ignorecase默认情况下为false ,并且仅对不支持区分大小写的文件系统添加优化。 Git thinks you deleted these files and added new ones when it detects case changes. Git认为您在检测到大小写变化时删除了这些文件并添加了新文件。 To prevent that unwanted behavior, you have to tell git that you're renaming them. 为了防止这种不良行为,您必须告诉git您正在重命名它们。

If true, this option enables various workarounds to enable Git to work better on filesystems that are not case sensitive, like FAT. 如果为true,则此选项启用各种变通办法,以使Git在不区分大小写的文件系统(例如FAT)上更好地工作。 For example, if a directory listing finds "makefile" when Git expects "Makefile", Git will assume it is really the same file, and continue to remember it as "Makefile". 例如,如果目录列表在Git期望“ Makefile”时找到“ makefile”,则Git将假定它确实是同一文件,并继续将其记住为“ Makefile”。

https://git-scm.com/docs/git-config#git-config-coreignoreCase https://git-scm.com/docs/git-config#git-config-coreignoreCase

alex:~/workspace/test (not_master) $ git mv readme.txt README.txt
alex:~/workspace/test (not_master) $ git status
On branch not_master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        renamed:    readme.txt -> README.txt

alex:~/workspace/test (not_master) $ 
alex:~/workspace/test (not_master) $ git commit -m "Renamed files"
[not_master 2b7c940] Renamed files
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename readme.txt => README.txt (100%)
alex:~/workspace/test (not_master) $ git push
alex:~/workspace/test (not_master) $ git checkout master
Switched to branch 'master'

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

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