如何使 git 接受模式更改而不接受所有文本更改?
我从“How do I make git”中得到了相反的问题忽略模式更改 (chmod)?" 我已经更改了一个文件的可执行权限,但也有一些文本更改,我想提交前者而不是后者。这可以用 git 实现吗?
(实际上,我已经做了一些想要与可执行权限更改一起提交的文本更改,以及其他我不想提交的文本更改)
更新:取消对文件的文本更改,然后再次执行 git add -p 并合并一些文本更改,成功地将模式更改转移到暂存中。 (我的git版本是1.5.4.3)
I've got the opposite problem from "How do I make git ignore mode changes (chmod)?" 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?
(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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该能够执行以下操作:
调整存储在索引中的可执行位。
然后,您可以将其与对文件内容的任何更改分开提交。
You should be able to do:
to adjust the executable bit stored in the index.
You can then commit this separately from any changes to the files content.
git add -i 可以让你有选择地从文件中添加一些块到索引中。我不知道它是否对权限敏感,但如果您要在 chmod 操作后添加一个块,即使没有显式更新权限,它也可能正确地出现在索引中。
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 thechmod
operation, it might end up in the index correctly even without explicitly updating the permission.查尔斯的回答
正在为我将文件模式和内容更改添加到索引中。我像这样解决了这个问题。
示例
或者你可以这样做
Charles’ answer
was adding both file mode and content changes to the index for me. I worked around it like this.
Example
Alternatively you can do