如何使 .gitattributes 的更改生效 [英] How to make change to .gitattributes take effect
问题描述
我正在做一个我们最近开始使用 git 的项目.设置从一开始就不是完美的,所以我在人们开始克隆/工作后设置了 .gitattributes,我仍在对该文件进行一些更改.
I'm working on a project where we have recently started using git. The setup was not perfect from start, so I've set up .gitattributes after people started cloning/working and I'm still making some changes to this file.
考虑以下设置...
Alice 和 Bob 都克隆了repo.git"并且存储库包含文件/myproj/src/file.ending 以
作为行尾,即文件不包含
个字符.
Both Alice and Bob have cloned "repo.git" and the repository contains the file /myproj/src/file.ending with
as line ending, i.e. the file does not contain
characters.
他们也都有 .gitattributes
具有以下设置:
They also both have .gitattributes
with the following setting:
/myproj/src/file.ending -text
这告诉 git file.ending
不应被视为文本文件,因此不应进行行结束转换.
This tells git that file.ending
should not be considered a text file and thus no line ending conversion should take place.
因此,Alice 和 Bob 的工作树中的文件也以
作为行结尾.
Accordingly, the files in Alice's and Bob's working tree also have
as line ending.
现在,Alice 对 .gitattributes 进行了以下更改:
Now, Alice makes the following change to .gitattributes:
/myproj/src/file.ending text
Alice 希望此更改对她和 Bob 都生效.
Alice would like this change to take effect, both for her and for Bob.
我现在知道的唯一方法是相当侵入性:
The only way I know of right now is quite intrusive:
git rm --cached -r .
git reset --hard
我想避免两件事:
- Alice 必须先提交她的 .gitattributes 文件,然后才能实际测试它(上面的重置将覆盖她的更改).
- Bob 必须擦除他的索引和工作树才能获得更新.鲍勃不高兴.
这样做的首选方法是什么?
What is the preferred way of doing this?
推荐答案
你不必硬重置(如果我理解正确的话).
You don't have to reset hard (if I understand correctly what you're doing).
我的情况类似.我在一个正在运行的项目中添加了一个 .gitattributes
.我需要我拥有的文件和在线 repo 中的文件由 gitattr 管理.
My case is similiar. I added a .gitattributes
in a running project. I need the files I have and the files in online repo to be ruled by gitattr.
# This will force git to recheck and "reapply" gitattributes changes.
git rm --cached -r .
git add -A
您的提交将重新添加您提到的所有 .ending
文件,并且您不会丢失您可能拥有的任何更改.当然,Bob 必须拉动才能得到它.
Your commit will re-add all the .ending
files you mention and you'll not lose any changes you may have. Of course, Bob will have to pull to get it.
这篇关于如何使 .gitattributes 的更改生效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!