How to make change to .gitattributes take effect

jgreen81 picture jgreen81 · Feb 6, 2018 · Viewed 7.8k times · Source

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:

  • Alice has to commit her `.gitattributes` file before she can actually test it (reset above will overwrite her changes).
  • Bob has to wipe his index and working tree to get the update. Bob is not happy.

What is the preferred way of doing this?

Answer

Ratata Tata picture Ratata Tata · Aug 31, 2018

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.