Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With git, temporary exclude a changed tracked file from commit in command line

Tags:

git

I have a tracked database (already added) file in git. I want this file to always contain the same data in my git repository. Even when I modify it in the working copy (local sandbox) for test purposes.

With git, how to exclude this changed file on my working copy from a commit ?

like image 311
djondal Avatar asked Jul 28 '10 15:07

djondal


People also ask

How do you exclude a file from a git commit?

Set “–assume-unchanged” to a path to exclude to check on git commit and it will exclude your file from git commit. You will need to use the git update-index and –assume-unchanged to exclude files from git commit.

How do I ignore a tracked file?

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 do I remove a file from being tracked by git?

To remove a file from Git, you have to remove it from your tracked files (more accurately, remove it from your staging area) and then commit. The git rm command does that, and also removes the file from your working directory so you don't see it as an untracked file the next time around.

How do I ignore changes in git?

Use Git update-index to ignore changes To resume tracking, run the git update-index command with the --no-skip-worktree flag. Or, you can temporarily stop tracking a file and have Git ignore changes to the file by using the git update-index command with the assume-unchanged flag.


3 Answers

The way to ignore certain files that are already committed is

git update-index --assume-unchanged file

However, this is a local setting, and it doesn't propagate when cloning.

Its effect is canceled with git update-index --no-assume-unchanged gui.

like image 138
P Shved Avatar answered Nov 07 '22 06:11

P Shved


Additionally to using git add I would suggest to use a shell with more capabilities, i.e. zsh. Here you can insert extended globbing like *~*.o(.) which means all files except such ending with o. This make it easier to add all files except one. Zsh also allows you to set a global alias: alias -g AF="*~*.o(.)". So you can type git add AF and it will be expanded in the right way.

like image 41
qbi Avatar answered Nov 07 '22 06:11

qbi


If you don't do git commit -a, git commit will only commit files that you have explicitly added to the index using git add.

like image 2
jdizzle Avatar answered Nov 07 '22 06:11

jdizzle