git commit -a: Stages files automatically
# Stage all modified files in the repository
$ git commit -a
# Stage all modified files in the repository and provide a commit message
$ git commit -a -m "Commit message"
git log -p: Produces patch text
# Show the patch text for all commits in the repository
$ git log -p
# Show the patch text for the last 5 commits in the repository
$ git log -p -5
git show: Shows various objects
# Show the details of the latest commit in the repository
$ git show
# Show the details of a specific commit in the repository
$ git show <commit-hash>
# Show the differences between the current branch and the latest commit
$ git diff
# Show the differences between two specific commits
$ git diff <commit-hash1> <commit-hash2>
# Show the differences between the staged files and the latest commit
$ git diff --staged
# Review patches interactively before adding to the current commit
$ git add -p
# Move a file in the repository
$ git mv <old-file-name> <new-file-name>
# Remove a file from the repository
$ git rm <file-name>
# Remove a file and stage the deletion for commit
$ git rm -f <file-name>
There are many useful git cheatsheets online as well. Please take some time to research and study a few, such as this one.
.gitignore files are used to intentionally tell the git tool to ignore some files in a given Git repository. For example, this can be useful for configuration or metadata files that a user may not want to check into the master branch. Check out more at: https://git-scm.com/docs/gitignore.
A few common examples of file patterns to exclude can be found here.
Git Branches and Merging Cheat Sheet
git branch <name>
git branch -d <name>
git branch -D <name>
git checkout <branch>
git checkout -b <branch>
Creates a new branch and switches to it.
git merge <branch>
git merge --abort
If there are merge conflicts (meaning files are incompatible), --abort can be used to abort the merge action.
git log --graph --oneline
Git Revert Cheat Sheet
git checkout is effectively used to switch branches.
git reset basically resets the repo, throwing away some changes. It’s somewhat difficult to understand, so reading the examples in the documentation may be a bit more useful.
Some other useful online articles discuss more aggressive approaches to resetting the repo.
git commit --amend is used to make changes to commits after-the-fact, which can be useful for making notes about a given commit.
git revert makes a new commit which effectively rolls back a previous commit. It’s a bit like an undo command.
There are a few ways you can roll back commits in Git.
There are some interesting considerations about how git object data is stored, such as the usage of sha-1.
Feel free to read more here: