Amend a commit
Add a change to the last commit:
1
| git commit --amend -m 'my new commit message'
|
Checkout a file vs a branch
The syntax for checking out a branch and a file are the same in git.
Suppose you have a file named ‘master’ and a branch named ‘master’. This checks out the branch:
1
| git checkout master #=> Already on 'master'
|
Whereas you can use the --
option to explicitly checkout a file:
Checkout a particular version of a file
From this StackOverflow answer:
1
| git checkout SHAabcde file/to/restore
|
Checkout an earlier version of a branch
1
| git co master@{one.month.ago}
|
Create a new branch
(while specifying your current branch as upstream)
1
| git co -b my_new_branch_name
|
Deleting a branch
1
| git branch -d the_local_branch
|
Global Gitignore
From the Github documentation:
1
| git config --global core.excludesfile ~/.gitignore_global
|
There’s also a good sample global gitignore file.
Rebasing a branch
Renaming a remote branch
1
| git remote rename original-name new-name
|
Removing a remote branch
1
| git remote remove origin
|
Pruning local branches
After fetching, remove any remote-tracking branches which no longer exist on the remote.
Tags
List tags:
Create a new tag:
Push a tag:
1
| git push origin v201412-rc1
|
Undoing the latest local commit
1
| git reset --soft 'HEAD^1'
|
References: