Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between `git rm --cached` and `git update-index --assume-unchanged`?

I do not understand the difference between git rm --cached and git update-index --assume-unchanged.

I'm aware that git rm --cached <file> will remove a file from the staging area.

And, I know that git update-index --assume-unchanged <file> also does this.

I've also seen both commands offered as suggestions to similar questions here on SO.

Is there another affect of either of these two commands that makes them different?

like image 905
makansij Avatar asked Oct 30 '15 04:10

makansij


People also ask

What is assume unchanged in git?

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.

What is difference between git rm cached and reset?

git rm —cached file will remove the file from the stage. That is, when you commit the file will be removed. git reset HEAD — file will simply reset file in the staging area to the state where it was on the HEAD commit, i.e. will undo any changes you did to it since last commiting.

What is git rm -- cached?

The Git rm –cached flag removes a file from the staging area. The files from the working directory will remain intact. This means that you'll still have a copy of the file locally. The file will be removed from the index tracking your Git project.


1 Answers

The command

git rm --cached <file>

is used to untrack files in a Git branch. This command will remove the file from the staging area and also will remove the file from the repository next time you commit.

The command

git update-index --assume-unchanged <file>

will also make the file disappear from the staging area. However, this command is different because it tells Git to only temporarily ignore any changes made to the file. So when you commit the file it will remain a part of the repository assuming it were already there. When you want Git to see the changes made to the file again, you can run this:

git update-index --no-assume-unchanged <file>

This will return the file to the staging area, if it were there when you ran assume-unchanged earlier.

Here is a link for git rm --cached, and here is a link for git update-index --assume-unchanged.

like image 169
Tim Biegeleisen Avatar answered Sep 28 '22 05:09

Tim Biegeleisen