Git Flashcards
git init
Turns the working directory into the Git working directory and creates a repository
Repository
A folder whose contents are tracked by Git
.git folder
This folder contains all the files and folders required by Git to keep track of all the changes done to the files within this repo.
If you delete the “.git” folder, Git will not identify this folder as a repo nor track its contents. You will lose all of the historical changes.
git status
if you want to see what is being tracked by Git within a repository
git add .
Stages the files in this directory to be committed
git commit -m “message”
commits your work to your local repository with the message given
Rebasing
essentially takes a set of commits, “copies” them, and plops them down somewhere else.
HEAD
HEAD is the symbolic name for the currently checked out commit – it’s essentially what commit you’re working on top of.
HEAD always points to the most recent commit which is reflected in the working tree.
Specifying commits with the caret operator
Each time you append that to a ref name, you are telling Git to find the parent of the specified commit.
So saying main^ is equivalent to “the first parent of main”.
main^^ is the grandparent (second-generation ancestor) of main
Using the ~ operator to move commits
The tilde operator (optionally) takes in a trailing number that specifies the number of parents you would like to ascend.
git checkout main~3
git branch -f main HEAD~3
Moves the pointer for main to 3 commits before the current HEAD
git reset HEAD~1
Points HEAD back one commit
git revert HEAD
creates a new commit that is the same as the one directly before HEAD
git cherry-pick <Commit1> <Commit2> <...></Commit2></Commit1>
It’s a very straightforward way of saying that you would like to copy a series of commits below your current location (HEAD)
git cherry-pick c1
git cherry-pick will plop down a commit from anywhere in the tree onto HEAD (as long as that commit isn’t an ancestor of HEAD).
in this case c1
git tag v1 c1
Tags c1 with the label v1 permanently
git rebase -i HEAD~3
Gives you an interactive choice of both which of the last 3 commits you’d like to keep and in what order, and appends them to the commit 3 above head.
Additionally the latest point in that branch (and HEAD) is at the new latest commit you appended
git describe <ref></ref>
If you don’t specify a ref, then HEAD is used
The output looks like:
<tag>_<numCommits>_g<hash>
Where tag is the closest ancestor tag in history, numCommits is how many commits away that tag is, and <hash> is the hash of the commit being described.
</hash></hash></numCommits></tag>