Git Flashcards
git status
List which files are staged, unstaged, and untracked.
git log
Display the entire commit history using the default format.
git log shows the current HEAD and its ancestry. That is, it prints the commit HEAD points to, then its parent, its parent, and so on. It traverses back through the repo’s ancestry, by recursively looking up each commit’s parent.
git diff
Show unstaged changes between your index and
working directory.
git revert
<commit>
</commit>
Create new commit that undoes all of the changes made in
<commit>, then apply it to the current branch.
</commit>
git reset <file></file>
Remove <file> from the staging area, but leave the working directory
unchanged. This unstages a file without overwriting any changes</file>
git clean -n
Shows which files would be removed from working directory.
Use the -f flag in place of the -n flag to execute the clean.
git commit
–amend
Replace the last commit with the staged changes and last commit
combined. Use with nothing staged to edit the last commit’s message.
git rebase <base></base>
Rebase the current branch onto <base></base>. <base></base> can be a commit ID,
branch name, a tag, or a relative reference to HEAD.
git reflog
**Show a log of changes to the local repository’s HEAD.
**
doesn’t traverse HEAD’s ancestry at all. The reflog is an ordered list of the commits that HEAD has pointed to: it’s undo history for your repo. The reflog isn’t part of the repo itself (it’s stored separately to the commits themselves) and isn’t included in pushes, fetches or clones; it’s purely local.
git branch
List all of the branches in your repo. Add a <branch> argument to
create a new branch with the name <branch>.</branch></branch>
git checkout -b
<branch>
</branch>
Create and check out a new branch named <branch>.</branch>
Drop the -b flag to checkout an existing branch.
git merge <branch></branch>
Merge <branch> into the current branch.</branch>
git pull <remote></remote>
Fetch the specified remote’s copy of current branch and
immediately merge it into the local copy
git push
<remote> <branch>
</branch></remote>
Push the branch to <remote>, along with necessary commits and
objects. Creates named branch in the remote repo if it doesn’t exist</remote>
Git rebase
git rebase, on the other hand, is another way to integrate changes from one branch to another, but it works a bit differently. Instead of creating a new merge commit, git rebase moves or merges commits, creating a linear commit history.