Skip to content

Instantly share code, notes, and snippets.

@paulschick
Created July 4, 2023 21:08
Show Gist options
  • Save paulschick/7f20646baadf2fb4d4c9dddd065bbcd1 to your computer and use it in GitHub Desktop.
Save paulschick/7f20646baadf2fb4d4c9dddd065bbcd1 to your computer and use it in GitHub Desktop.
A cheetsheat for git update-index operations.

Git Index Cheat Sheet

Overview

The Git index is known as the staging area. This is where you can manipulate tracked files. We'll focus on git update-index to manage files that are assumed unchanged.

Commands

Mark a File as Unchanged

Use this to tell Git to assume that a file has not changed, even if it has. This is useful for modification of files locally without committing the changes.

git update-index --assume-unchanged [file]

Stop Assuming a File is Unchanged

Use this command to tell Git to stop assuming that a file is unchanged and start tracking it again.

git update-index --no-assume-unchanged [file]

View Files Assumed Unchanged

When you want to see a list of all files that are assumed unchanged, use this command.

git ls-files -v | grep '^h'

This command will show you a list of all files that are assumed unchanged. The -v flag will show you the files that are assumed unchanged. The grep command will filter the output to only show files that are assumed unchanged. Files that are assumed unchanged will have an h in the first column of the output.

Stop Assuming All Files are Unchanged

The following helper script will stop assuming all files are unchanged.

for file in $(git ls-files -v | grep '^h' | awk '{print $2}'); do git update-index --no-assume-unchanged $file; done

Further Notes

Working with the Git index is a low-level operation. The index is typically interacted with through commands like git add and git reset. Being aware of git update-index operations can give you more control over Git operations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment