Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git ignore local changes to portions of tracked files

Tags:

git

Specifically, I maintain a git repository of my dotfiles. I recently started working on a new machine and cloned my repository on the same.

Now, I wish to make some changes to my dotfiles which are specific to this system only. These changes I wish to ignore in my repository.

Other changes that I make, should continue to be tracked and committed.

For example, in my .gitconfig, I have a setting as:

[push]    default = simple 

Now, on my new machine, the version of git being used it very old. It still not not support the setting simple for push. So, I'd like to change this, but only locally.

However, if I make any other changes to my .gitconfig, I'd like to keep track of those. Anyway I can achieve this?

EDIT:
I know of git update-index --assume-unchanged. The problem with it is that git will no longer track my file at all, until I reverse it. And then, it will track all changes.
I wish to ignore certain changes and track the rest.

like image 367
darnir Avatar asked Feb 13 '14 14:02

darnir


People also ask

How do I configure Git to ignore some files locally?

If you want to ignore certain files in a repository locally and not make the file part of any repository, edit . git/info/exclude inside your repository.

How do I ignore changes to a file in Git?

In the Git Changes window, right-click any changed file that you want Git to ignore and choose Ignore this local item or Ignore this extension. Those menu options don't exist for tracked files.

How do I ignore tracked files in Git?

Simply move the files to a folder outside of git, then do "git add .", "git commit". (This removed the files) then add the gitignore, referencing the files/folders, commit again to add the gitignore file to git, then copy/move back in the folders, and they should be ignored.

How would you best force Git to not track changes a file or directory?

What you probably want to do is this: git update-index --skip-worktree . (The third option, which you probably don't want is: git rm --cached .


2 Answers

Try using this command:

git update-index --assume-unchanged FILENAME_TO_IGNORE 

To reverse it (if you ever want to commit changes to it), use:

git update-index --no-assume-unchanged 

UPDATE:

Here's how to list 'assume unchanged' files under current directory:

git ls-files -v | grep -E "^[a-z]" 

As the -v option will use lowercase letters for 'assume unchanged' files.

like image 144
atupal Avatar answered Oct 11 '22 12:10

atupal


I don't believe there's a specific command that will 'untrack' certain changes to a file. However, there's no reason that you couldn't create a local branch into which you pull changes from your remotes, but never send any changes back.

like image 44
Peter Bratton Avatar answered Oct 11 '22 14:10

Peter Bratton