Skip to content

Instantly share code, notes, and snippets.

@aneurysmjs
Last active July 6, 2023 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aneurysmjs/070209e06652dcc2514f8b8ef74f3731 to your computer and use it in GitHub Desktop.
Save aneurysmjs/070209e06652dcc2514f8b8ef74f3731 to your computer and use it in GitHub Desktop.
git tricks

ignore files temporarily

start ignoring changes to a file:

git update-index --assume-unchanged path/to/file

keep tracking again:

git update-index --no-assume-unchanged path/to/file

see here

get a list of files marked --assume-unchanged:

git ls-files -v | grep '^[[:lower:]]'

list files in a commit

see here

git diff-tree --no-commit-id --name-only -r 'hash of the commit'

--no-commit-id suppresses the commit ID output.
--pretty argument specifies an empty format string to avoid the cruft at the beginning.
--name-only argument shows only the file names that were affected (Thanks Hank).
Use --name-status instead, if you want to see what happened to each file (Deleted, Modified, Added)

-r argument is to recurse into sub-trees

add missing file to last commit

see here

git add the_left_out_file
git commit --amend --no-edit

fetch main and merge without changing branch

git fetch origin main
git merge origin/main

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