Git

How Does git update-index –assume-unchanged do?

Git developers are permitted to ignore the files temporarily. They can perform this operation for multiple purposes, such as when they need to work more on this particular file but don’t want to push it to the Git repository or perform more experiments without adding it to the Git directory. In these situations, they can use the “git update-index” command. This command supports the “–assume-unchanged” option for telling Git to temporarily assume that the specified tracked file has not been modified in the Git working tree.

This blog will talk about:

What Does git update-index –assume-unchanged <file> Do?

To ignore the specific Git file, implement the below-given steps:

  • Go to the Git repository.
  • List current repository content.
  • Select the desired file which needs to be ignored.
  • Execute the “git update-index –assume-unchanged <dir/file-name>” command.

Step 1: Move to Git Repository

At first, switch to the specified path with the help of the “cd” command:

$ cd "C:\Users\nazma\Git\test1"

Step 2: List Repository Content

Now, display the existing content of the repository through the following command:

$ ls

Here, we have selected the highlighted file name for further operation:

Step 3: Update File Index

Next, switch to the root directory and execute the “git update-index” command to update the index of the selected file:

$ git update-index --assume-unchanged test1/file3.txt

In the above-stated command, the “–assume-unchanged” option is used for modifying the required file and “file1/file3.txt” is our desired file:

Step 4: Verification

After that, to verify whether the target file is ignored successfully or not, run the “git ls-files” command along with the “-v” option:

$ git ls-files -v

According to the below-given output, the “h” status beside the highlighted “file3.txt” name indicates that the index of this particular file has been ignored temporarily:

How to Change Ignored File Status to “–no-assume-unchanged”?

If you want to change the index value and do not assume the unchanged, then utilize the following command:

$ git update-index --no-assume-unchanged test1/file3.txt

Here, the “–no-assume-unchanged” option is used to unset the status of the ignored file:

Run the following command to ensure the modified status of the ignored file:

$ git ls-files -v

In the below-provided output, the status of the ignored file has been changed to “H”:

That’s all! We have explained the method to ignore and unset the file status.

Conclusion

To ignore the specific Git file, first, move to the Git repository and list its content. Then, select the desired file which needs to be ignored and run the “git update-index –assume-unchanged <dir/file-name>” command. If you want to change a particular file status from ignored to default, execute the “git update-index –no-assume-unchanged <dir/file-name>” command. This blog illustrated the process of ignoring and unsetting the file status.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.