当我输入时git status
,我看到:
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: DIR/a
#
Run Code Online (Sandbox Code Playgroud)
但是,在我的工作目录中,我看到实际调用了这个文件dir/a
(注意小写dir
而不是DIR
).
问题:我想将此修改后的a
文件添加到临时区域并提交,但我希望它与我的工作目录(显示dir/a
)一样 - 而不是git看到它的方式DIR/a
.我怎样才能做到这一点?
重要的提示:
不幸的是,我不能简单地git mv DIR/a dir/a
因为DIR/a
工作树中实际上并不存在.
目前我的.git/config
文件显示ingorecase = true
,所以我知道我必须设置等于false.但是,除了改变这个标志之后什么都没做,git status
现在有一个显示:
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: DIR/a
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# dir/
Run Code Online (Sandbox Code Playgroud)
我期待这个,因为git只跟踪内容,切换ignorecase会让git认为添加了一个新文件.不幸的是,git现在认为我有两个被修改的文件,而实际上我只有一个.我想git status
简单地显示dir/a
(因为它在我的工作目录中)而不是DIR/a
,a
我刚刚做了相同的差异.
附加说明
如果你是好奇,这样一个不稳定的局势摆在首位如何产生的,我已成功地复制时,最初是从我改名目录的情况下,我做出了愚蠢的错误DIR
来dir
.如果你认为这有助于找到解决这个问题的方法,我很乐意做一个编辑,揭示我如何错误地让git如此困惑.(它涉及我不小心撞击mv
而不是git mv
意识到ignorecase
旗帜而留下它ignorecase=true
).
小智 52
例如:如果你是低层Mydir
git mv src/Mydir src/mydirs
git mv src/mydirs src/mydir
git commit -m "Rename folder Mydir to mydir"
Run Code Online (Sandbox Code Playgroud)
sma*_*oun 19
我找到了一个解决方法.我不确定是否有一个更优雅的解决方案,但我已经测试了它,它确实有效.因为当只有一个文件时git继续认为存在两个文件,我实际上只需要完全复制目录,删除git跟踪的文件,然后将复制的目录复制回原始目录.
(1)提交dir
需要提交的任何文件.
(2) cp -r dir tempDir
(3) git add tempDir/
(4) git rm -r dir Dir
(5) git commit -m "Temporary rename of dir to tempDir"
(6) git mv tempDir mms
(7) git commit -m "Full rename from DIR to dir complete"