Skip to content

Instantly share code, notes, and snippets.

@zakelfassi
Last active August 29, 2015 14:05
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 zakelfassi/d9d7870e30d21d2cf213 to your computer and use it in GitHub Desktop.
Save zakelfassi/d9d7870e30d21d2cf213 to your computer and use it in GitHub Desktop.
GitTricks.sh
# GIT Tricks.
Delete from git all deleted system files:
git rm $(git ls-files --deleted)
View deleted file:
git show HEAD^:path/to/file
git show $(git rev-list --max-count=1 --all -- foo)^:foo
## File fixes
```git reset HEAD <path/to/file>``` Unstage a file. (HEAD represents the current commit)
```git reset HEAD``` Unstage all staged files.
```git checkout <path/to/file>``` To revert to the last committed version of a file but only if a) the file has been committed and b) is not currently in staging
```git checkout HEAD^ <path/to/file>``` Revert to version of file from prior commit (HEAD^ represents the prior commit). Careful: this overwrites changes to files in your working branch.
```git checkout <sha-of-commit> <path/to/file>``` Revert to version of file from specific commit
## Undo commits
only use it to back out of local commits that haven not been pushed to a shared repository.
```git reset --soft HEAD^``` Undo last commit of entire repo, but leave files staged.
```git reset --hard HEAD^``` Completely blow away last commit. Changes files to state of previous commit.
```git reset --hard HEAD^^``` Completely blow away last two commits. Changes files to state of previous commit.
```git reset --hard HEAD^^^``` Completely blow away last three commits. Changes files to state prior to last third commit.
```git reset --hard <sha-of-commit>``` Returns files to state they were in after specificed commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment