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.
Consider the following setup...
Both Alice and Bob have cloned "repo.git" and the repository contains the file /myproj/src/file.ending with \n
as line ending, i.e. the file does not contain \r
characters.
They also both have .gitattributes
with the following setting:
/myproj/src/file.ending -text
This tells git that file.ending
should not be considered a text file and thus no line ending conversion should take place.
Accordingly, the files in Alice's and Bob's working tree also have \n
as line ending.
Now, Alice makes the following change to .gitattributes:
/myproj/src/file.ending text
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
I would like to avoid two things:
What is the preferred way of doing this?
gitattributes file allows you to specify the files and paths attributes that should be used by git when performing git actions, such as git commit , etc. In other words git automatically saves the file according to the attributes specified, every time a file is created or saved.
These path-specific settings are called Git attributes and are set either in a . gitattributes file in one of your directories (normally the root of your project) or in the . git/info/attributes file if you don't want the attributes file committed with your project.
You don't have to reset hard (if I understand correctly what you're doing).
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
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.
osse
on irc://chat.freenode.net/#git
gave me this method, and it works reasonably well:
git rm -r :/ && git checkout HEAD -- :/
This will complain if you have uncommitted changes in your tree.
Seems like there should be a better way though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With