Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make change to .gitattributes take effect

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?

like image 419
jgreen81 Avatar asked Feb 06 '18 12:02

jgreen81


People also ask

How do I use .gitattributes file?

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.

Where is my .gitattributes file?

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.


2 Answers

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.

like image 193
Ratata Tata Avatar answered Oct 06 '22 08:10

Ratata Tata


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.

like image 20
Iwan Aucamp Avatar answered Oct 06 '22 08:10

Iwan Aucamp