Git Flashcards
To restore deleted and staged files
git reset HEAD followed by
git checkout HEAD
to see the remotes associated with your local repository.
git remote -v
git diff compares your working tree
to the staging area
git diff –staged to compare to staging area
git log -p
to see every detail of your commits, such as the actual changes, or diff, of each commit.
The working tree is
the collection of project files that you work with directly.
Git thinks about the files in your working tree as being in three distinct states:
unmodified, modified and staged.
/.html matches
all files with an .html extension, but only in subdirectories of your project.
Graphical views of your repository
git log –graph
git log –oneline –graph
o tell Git to show you the complete history of everything it knows about
git log –oneline –graph –all
Searching Git history commands
git log --author=crispy8888 --oneline git log --grep=ideas --oneline git log --oneline books/book_ideas.md git log --oneline --stat books books - directory To see changes in directory git log -S"Fortran"
Find all of the commits in your code that deal with the term “Fortran”
git log -S”Fortran”
git log -S”Fortran” -p (with details)
to see all local branches.
git branch
brings the commits from the remote repository and merges them with your local commits.
git pull
pulls all of the commits down from the remote repository to your local
one.
git fetch
You can’t push to a remote that has
any commits that you don’t have locally, and that Git can’t fast-forward merge.
to add a remote to your local repository.
git remote add origin
to push the local commits in your repository to your remote, and to start tracking your local branch against the remote branch.
git push–set-upstream origin master or git push -u origin master
How Git reconstruct a branch, based on a single commit hash step by step
You switch to a named branch, which is a label that references a commit hash.
Git finds that commit object by its hash, then it gets the tree hash from the commit object.
Git then recurses down the tree object, uncompressing file objects as it goes.
Your working directory now represents the state of that branch as it is stored in the repo.
Gits the most common objects
Commits: Structures that hold metadata about your commit, as well as the pointers to the parent commit and the files underneath.
Trees: Tree structures of all the files contained in a commit.
Blobs: Compressed collections of files in the tree.
git rev-parse
will translate a short hash into a long hash
git cat-file
will show you the pertinent metadata about an object.
git status -sb
gives a concise view of the state of your working tree.
starts an interactive rebase operation.
git rebase -i
You can move lines around in the rebase script to
reorder commits.
What cloning repository automatically do?
Cloning a repository automatically creates a hidden .git directory, which tracks the activity on your local repository.
What Forking do?
Forking creates a remote copy of a repository under your personal user space.
Git thinks about the files in your working tree as being in three distinct states
Unmodified •
Modified•
Staged
With git add .
to put everything from your working tree into the staging area
How Git views your working tree?
At its core, Git really only knows about files, and nothing about directories. Git thinks about files as string that point to entities Git can track.
How to commit an empty directory?
placeholder file. The usual convention is to create a hidden, zero-byte .keep file inside the directory you want Git to “see.”
A commit is essentially
a snapshot of the particular state of the set of files in the repository at a point in time
git status
shows you the current state of your working tree.
git add
lets you add changes from your working tree to the staging area.
git add .
adds all changes in the current directory and its subdirectories.