Git cheatsheet

By   07-08-2015 · 2 minute read · 229 words


I leverage Git on a daily basis to add and track changes. But often other less used commands such as tag, amend, are often forgotten or I forget how to use them. Here’s a complete list of useful Git one liners I reference when I get stuck.

Tagging a previous commit so we can roll back to it for builds.

git tag -a v4.4 ac903bf -m "My tag message"

Where ac903bf = commit id and 4.4 = the tag id.

Displaying your tag.

git show 4.4

Returns you the commit details for the tag.

Reverting to a previous commit.

git checkout ac903bf

This will bring you back to a previous commit, the hash is from the commit history obtained from “git log”. You can also substitute the commit with the tag from the tag one liner above.

Undoing changes of last commit

git revert --no-edit ac903bf

If you’ve made an edit and wish to undo the changes of that commit the revert command will do this.

Viewing the difference between what the last commit was and now

git diff HEAD^ HEAD

Fixing a commit name that you mispelled or described incorrectly.

git commit amend -a -m "Your revised/mispelled message"

Reset a staged file prior to check in

Leverage this when you stage a file accidentally and don’t want to commit it. This will unstage it.

git reset head path/to/file/to/reset

git  

comments powered by Disqus