0

Perhaps a duplicate, but haven't found an answer to this question.

We have a repository, and the repository contains some tracked files, for example, the ".gitignore" file, as well as "conf" folder.

I want to exclude tracking this file and folder because it contains changes that will only work on my machine, and where I don't want to disrupt the settings of others by committing my changes to these config files.

Adding this file and folder in ".gitignore" doesn't help since it still being tracked.

How can I avoid tracking these changes in these files?

Xeizzeth
  • 441
  • 1
  • 3
  • 10
  • What specifically do you mean by "exclude tracking this file"? Do you mean that when people run `git log` they should not see it? – Mort Oct 02 '18 at 14:22
  • I mean - I don't want to commit my changes so they won't appear in the repository. – Xeizzeth Oct 02 '18 at 14:23
  • 1
    If there are entries in the .gitignore that are only relevant to your machine that are checked in, you should remove those entires and commit the change. Move those entries to `$HOME/.config/git/ignore` or `$GIT_DIR/info/exclude` depending on if they are global to your machine or specific to the project. – William Pursell Oct 02 '18 at 14:29
  • Note that if others complain that those entries were needed for their workflow, you should have them add the entries the the appropriate location on their box. – William Pursell Oct 02 '18 at 14:31
  • Thank you, William, what if you put this information in the answers section, instead of comments? Because while I already received the (perhaps) working solution, the others could find your solution more satisfiable. – Xeizzeth Oct 02 '18 at 14:32

1 Answers1

0

What you want is setting the flag assume-unchanged. You can use git update-index for that purpose:

git update-index --assume-unchanged .gitignore

Later, if you want to unset the flag to commit the changes on the fil, use

git update-index --no-assume-unchanged .gitignore

For more information, refere to git doc:

--[no-]assume-unchanged

When this flag is specified, the object names recorded for the paths are not updated. Instead, this option sets/unsets the "assume unchanged" bit for the paths. When the "assume unchanged" bit is on, the user promises not to change the file and allows Git to assume that the working tree file matches what is recorded in the index. If you want to change the working tree file, you need to unset the bit to tell Git. This is sometimes helpful when working with a big project on a filesystem that has very slow lstat(2) system call (e.g. cifs).

Git will fail (gracefully) in case it needs to modify this file in the index e.g. when merging in a commit; thus, in case the assumed-untracked file is changed upstream, you will need to handle the situation manually.

EDIT

To apply the flag on folder, you need to execute the command for each file in the folder. See this answer for hints to perform this task automatically (if your folder contains many files). Example:

cd /path/to/the/folder
git ls-files -z | xargs -0 git update-index --assume-unchanged
Antwane
  • 20,760
  • 7
  • 51
  • 84