Git Cheatsheet
# show individual files in untracked directories
git status -u (--untracked-files)
# let you also record the removals.
git add -A (--all)
# ignores paths you removed from your working tree
git add --ignore-removal
# Git add files in directory recursively
git add {directory_name}
# Git wildcard
git add '*.txt'
git rm '*.txt'
# Combine the staged changes with the previous commit and replace the previous commit with the resulting snapshot. Running this when there is nothing staged lets you edit the previous commit’s message without altering its snapshot.
git commit --amend
git commit --amend --no-edit (allow you to make the amendment to your commit without changing its commit message)
# search git logs
git log --all --grep='xxx'
# Temporary switching to a different commit
git checkout {commit}
# Check out a previous version of a file. This turns the <file> that resides in the working directory into an exact copy of the one from <commit> and adds it to the staging area.
git checkout {commit} {file}
# To return
git checkout {branch}
# Git Revert
git revert {commit}
# Revert last 3 commits (-n = no commit)
git revert -n master~3..master
# Check difference between working relative to commit
git diff {commit}
# Undo git add
git reset {file}
# Reset the staging area to match the most recent commit, but leave the working directory unchanged.
git reset
# Move the current branch tip backward to <commit>, reset the staging area to match, but leave the working directory alone. All changes made since <commit> will reside in the working directory, which lets you re-commit the project history using cleaner, more atomic snapshots.
git reset {commit}
# Reset the entire repository to the last committed state
git reset --hard
# Remove a git commit which has not pushed
git reset --hard HEAD^
# Remove untracked files
git clean -f
-d (remove directories)
-x (remove ignored files)
-X (remove only ignored files)
# Remove tracking a file
git rm
-f (remove if there are local changes)
# ignore file mode changes
git config core.fileMode false