Skip to content

Instantly share code, notes, and snippets.

@marianposaceanu
Last active December 20, 2015 06:39
Show Gist options
  • Select an option

  • Save marianposaceanu/6087784 to your computer and use it in GitHub Desktop.

Select an option

Save marianposaceanu/6087784 to your computer and use it in GitHub Desktop.

Basic git tips

Issue with missing tracked files
git update-index --assume-unchanged my-tracked-file-that-is-awol
git status -u --ignored
git update-index --no-assume-unchanged my-tracked-file-that-is-awol
Remove file
git filter-branch --index-filter 'git rm -r --cached --ignore-unmatch <file/dir>' HEAD
Git GC
rm -rf .git/refs/original/ && git reflog expire --all &&  git gc --aggressive --prune
How to undo the last Git commit
$ git commit ...              (1)
$ git reset --soft 'HEAD^'    (2)
$ edit                        (3)
$ git add ....                (4)
$ git commit -c ORIG_HEAD     (5)

This is what you want to undo

This is most often done when you remembered what you just committed is incomplete, or you misspelled your commit message, or both. Leaves working tree as it was before "reset". (The quotes may or may not be required in your shell)

Make corrections to working tree files.

Stage changes for commit.

"reset" copies the old head to .git/ORIG_HEAD; redo the commit by starting with its log message. If you do not need to edit the message further, you can give -C option instead.

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