gpt4 book ai didi

macos - 在 OSX 上,git merge 删除重命名大写的文件

转载 作者:太空狗 更新时间:2023-10-29 13:45:48 24 4
gpt4 key购买 nike

我编写了这个脚本并在 OSX 10.8 Mountain Lion 上运行了它,在默认的不区分大小写的 HFS 文件系统上。

#!/bin/sh -x
# create git repo
rm -rf caps
git init caps
cd caps
# commit empty file called "file"
touch file
git add .
git commit -am "initial commit"
# create branch called "branch"
git branch branch
# rename "file" to "File"
# using --force per http://stackoverflow.com/questions/6899582
git mv --force file File
git commit -am "renamed capital"
# switch to branch, make a non-conflicting commit
git checkout branch
touch newfile
git add .
git commit -am "branch commit"
# merge master into branch, commit merge
git merge --commit --no-edit master
# but where's the renamed File?
more File

当脚本完成后,它在最后一行失败了,而它本应该成功:

+ git merge --commit --no-edit master
Removing file
Merge made by the 'recursive' strategy.
file => File | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename file => File (100%)
+ more File
File: No such file or directory

git status 显示了这个:

$ git status
# On branch branch
# Changes not staged for commit:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: File
#
no changes added to commit (use "git add" and/or "git commit -a")

此时我们可以使用 git checkout File 取回文件,但此时很容易意外提交删除。

我们最近重命名了很多文件,修复了它们的大小写问题,这对我们的团队造成了很大的影响。有没有我们可以用来解决这个问题的 git 设置或最佳实践? (目前,我们只是告诉大家要格外小心。)

最佳答案

那个问题(“删除重命名大写的文件”)恰好是什么commit ae352c7f37ef2098e03ee86bc7fd75b210b17683通过 David Turner (dturner-tw)解决:

merge-recursive.c : 修复改变大小写的 merge 错误

On a case-insensitive filesystem, when merging, a file would be wrongly deleted from the working tree if an incoming commit had renamed it changing only its case.
When merging a rename, the file with the old name would be deleted -- but since the filesystem considers the old name to be the same as the new name, the new file would in fact be deleted.

We avoid this by not deleting files that have a case-clone in the index at stage 0.

这意味着,从 git 2.0.1+(2014 年 6 月 25 日)开始, merge 现在应该可以进行了。

关于macos - 在 OSX 上,git merge 删除重命名大写的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19280930/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com