如何在不接受所有文本更改的情况下进行 git 接受模式更改?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1611211/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I make git accept mode changes without accepting all text changes?
提问by Andrew Grimm
I've got the opposite problem from "How do I make Git ignore file mode (chmod) changes?" I've got a file that I've changed executable permission on, but there are also some text changes, and I want to commit the former but not the latter. Is this possible with git?
我遇到了与“如何让 Git 忽略文件模式 (chmod) 更改?”相反的问题提交前者但不提交后者。这可以用 git 实现吗?
(Actually, I've made some text changes I want to commit along with the executable permission change, and others I don't want to commit)
(实际上,我已经进行了一些文本更改,我想与可执行权限更改一起提交,而其他一些我不想提交)
Update:Unstaging the text changes to the file, and then doing git add -p
again and incorporating some of the text changes managed to get the mode change
into staging. (My git version is 1.5.4.3)
更新:取消暂存对文件的文本更改,然后git add -p
再次执行并合并一些文本更改,设法将模式更改转换为暂存。(我的 git 版本是 1.5.4.3)
采纳答案by Bob Aman
git add -i
will let you selectively add some hunks from a file to the index. I don't know whether or not it's sensitive to permissions, but if you were to add a hunk after the chmod
operation, it might end up in the index correctly even without explicitly updating the permission.
git add -i
将让您有选择地将文件中的一些大块添加到索引中。我不知道它是否对权限敏感,但是如果您在chmod
操作后添加一个大块,即使没有明确更新权限,它也可能正确地在索引中结束。
回答by CB Bailey
You should be able to do:
你应该能够做到:
git update-index --chmod=(+|-)x <file>
to adjust the executable bit stored in the index.
调整存储在索引中的可执行位。
You can then commit this separately from any changes to the files content.
然后,您可以将其与对文件内容的任何更改分开提交。
回答by Steven Penny
Charles' answerwas adding both file mode and content changes to the index for me. I worked around it like this.
查尔斯的回答是为我将文件模式和内容更改添加到索引中。我像这样解决了它。
git update-index --skip-worktree --chmod=+x <file>
git update-index --no-skip-worktree <file>
Alternatively you can do
或者你可以做
git update-index --chmod=+x <file>
git config interactive.singlekey 1
echo na | git reset -p