backups + restores
$ git init # init a git reposotory, happens whne you start a new project
$ git clone # clone an existing repo
# .git is the repository that stores all the version info
After the clone, you can:
$ git diff # tell you the differences of the changes that you made
# compares the most recent version to the changes that you make
$ git status # tells you the current status: which files are modified, uncommitted etc.
.gitignore
has the information for what git is ignoring, or not keeping track of
Q: Which of your softwares' files should not be put under Git control?
/abc*def
matches only files at top leaves
!abc.o *.o
will ignore every .o file but abc.o
Check the history version
$ git log # there's a lot, lot, lot of options
# for instance, git log --pretty=fuller
This will outputs:
git ls-file
list all the files that git is in control of
grep Error $(git ls-file)
git grep Error # identical to above
To identify a commit, we can find a special value(40 chars) along with the commit that's the check sum calculated by the SHA-1 checksum. 1 in 2^160 chance that 2 SHA will collide. The SHA itself is extremely difficult to reverse-engineer
So how should we use it? git log A..b
will log everything e such that A < e < B, where A and B are ids. We don't have to use the full id and can just use first few characters too.
Also, there are the special alias HEAD that points to the most recent history
We can also do log by tag name like git log v3.8..HEAD
C^
just before C C~3
3 commits before C
git diff C^!
= git diff C^..C
git show C
showing everything about this particular commit C
git blame C --FILE
look at all the changes of FILE at commit C and the commit messages