Notes For Git
Settings
1 | $ git config --list --show-origin |
There levels: --local
> --global
> --system
On Windows systems, Git looks for the .gitconfig
file in the $HOME directory (C:\Users$USER for most people). It also still looks for [path]/etc/gitconfig
, although it’s relative to the MSys root, which is wherever you decide to install Git on your Windows system when you run the installer.
Basics
initializing
1 | $ cd D:/my_project |
to control a repository with git and this will create a file named .git
we can initialize a repository like this:
1 | $ git add *.c |
cloning
we can clone a repository like this:
1 | $ git clone https://github.com/ |
if want a new name
1 | $ git clone <url> name |
and there are other protocols that can be chosen(SSH)
recording changes
two states : tracked or untracked. To CHECK this :
1 | $ git status |
There are two columns to the output — the left-hand column indicates the status of the staging area and the right-hand column indicates the status of the working tree.
Ignoring Files
1 | - .gitignore |
Viewing Your Staged and Unstaged Changes
git diff
shows you the exact lines added and removed — the patch, as it were
Commit Your Changes
git commit
这样需要打开编辑器输入
git commmit -m "There is message"
1 | $ git commit -m "Story 182: fix benchmarks for speed" |
git commit -a
可以跳过stage阶段
Removing Files
remove it from your tracked files, and also removes the file from your working directory so you don’t see it as an untracked file the next time around
rm
直接删除,但是不stage
git rm
删除,但是已经stage
If you modified the file or had already added it to the staging area, you must force the removal with the -f
option.
to keep the file in your working tree but remove it from your staging area.
git rm --cached README
Moving Files
重命名
1 | $ git mv README.md README |
相当于
1 | $ mv README.md README |
Viewing the Commit History
git log
查看commit history
git log -patch
显示每次的commit的不同之处
git log -2
只看最近两条