Tricks

Undo unstaged work

Undo all changes that have not been staged or committed:

git reset --hard

Undo changes that have not been staged or committed to a file:

git checkout -- filename.txt

Undo commits

Undo last unpushed commit and keep changes in working directory:

git reset --soft HEAD^

Undo last unpushed commit and lose changes:

git reset --hard HEAD^

Rename a file

git mv oldFile.js newFile.js

Mac/Unix/Windows don’t have the same case-sensitivity in their filesystems. If renaming only affects capitalization, then git mv is the only way to apply the change across filesystems.

git mv somefile.js someFile.js

Diffing

# Generate diff and save to file
git diff --name-status {commit1} {commit2} > file.txt

# Example
git diff --name-status b521ddfd8064c622471e0dabc7db2cfcef536713 c300d0553a95c20317e1f35f998d76843ae97b35 > file.txt

Merging clean-up

# Check the repo for remnants of merge conflict comments
git diff --check

Delete a tag

First, delete all the tags in your local repo.

Second, delete the specific tag on the remote:

git push --delete origin {tag_name}

Third, pull the remote.