- treeish: anything which references a commit (e.g. branch, HEAD, HEAD
10, master15, SHA)
Displays file from a specific commit
Checkout a file from a specific commit
e.g.
git checkout HEAD~1 -- foo.php
- Checkout foo.php from the previous commit
git checkout -- foo.php
- Checkout foo.php from the current commit
git checkout master -- foo.php
- Checkout foo.php from master
Same as:
git branch <branch>
git checkout <branch>
Interactive mode add
Remove files from stage/index
Remove specific file from stage/index
Same as git reset
but also re-checkout files which has been modified
Rollback one commit from where you are now (HEAD)
Move your current HEAD (and branch) to a specific commit e.g. git reset origin/master --hard
to move your local master back to origin/master. Note that --hard
also resets your working directory
Stash your current changes and then get them back to the working copy. Whilst keeping the stash commit so if you mess up your working copy. You still got a stash copy!
Note: To stash new files, you must add them to the stage/index
Remove file form the latest commit
git rm <file>
git commit --amend
If the commit is older than 1 commit ago..
git rebase <treeish>~1 -i
Treeish being the commit the file was introduced on
select the appropriate commit and change to 'edit' (probably the top one)
git rm <file>
git commit --amend
git rebase --continue
- You might have to resolve conflicts if the file has been modified since it was added to git.