Git 是一种分布式版本管理工具。
$ tar zxf frotz.tar.gz
$ cd frotz
$ git init
$ git add . (1)
$ git commit -m "import of frotz source tree."
$ git tag v2.43 (2)
$ git checkout -b alsa-audio (1)
$ edit/compile/test
$ git checkout -- curses/ux_audio_oss.c (2) # 恢复文件
$ git add curses/ux_audio_alsa.c (3)
$ edit/compile/test
$ git diff HEAD (4) # 查看提交了哪些修改
$ git commit -a -s (5) # 提交所有
$ edit/compile/test
$ git diff HEAD^ (6) # 查看所有变化,包含之前的 commit
$ git commit -a --amend (7) # 修订前一个 commit, 把所有的新变化提交到
$ git checkout master (8)
$ git merge alsa-audio (9)
$ git log --since='3 days ago' (10)
$ git log v2.43.. curses/ (11)
## clone 修改 提交
$ git clone git://git.kernel.org/pub/scm/.../torvalds/linux-2.6 my2.6
$ cd my2.6
$ git checkout -b mine master (1)
$ edit/compile/test; git commit -a -s (2)
$ git format-patch master (3)
$ git send-email --to="person <email@example.com>" 00*.patch (4)
$ git checkout master (5)
$ git pull (6)
$ git log -p ORIG_HEAD.. arch/i386 include/asm-i386 (7) # 查看感兴趣的部分
$ git ls-remote --heads http://git.kernel.org/.../jgarzik/libata-dev.git (8) # 查看分支
$ git pull git://git.kernel.org/pub/.../jgarzik/libata-dev.git ALL (9) # 从一个特地
$ git reset --hard ORIG_HEAD (10) # 撤销 pull
$ git gc (11) # garbage collect leftover objects from reverted pull
# 推送到其他 repo
satellite$ git clone mothership:frotz frotz (1)
satellite$ cd frotz
satellite$ git config --get-regexp '^(remote|branch)\.' (2)
remote.origin.url mothership:frotz
remote.origin.fetch refs/heads/*:refs/remotes/origin/*
branch.master.remote origin
branch.master.merge refs/heads/master
satellite$ git config remote.origin.push \
+refs/heads/*:refs/remotes/satellite/* (3)
satellite$ edit/compile/test/commit
satellite$ git push origin (4)
mothership$ cd frotz
mothership$ git checkout master
mothership$ git merge satellite/master (5)
1. mothership machine has a frotz repository under your home directory; clone from it to start a repository on the satellite machine.
2. clone sets these configuration variables by default. It arranges git pull to fetch and store the branches of mothership machine to local remotes/origin/* remote-tracking
branches.
3. arrange git push to push all local branches to their corresponding branch of the mothership machine.
4. push will stash all our work away on remotes/satellite/* remote-tracking branches on the mothership machine. You could use this as a back-up method. Likewise, you can
pretend that mothership "fetched" from you (useful when access is one sided).
5. on mothership machine, merge the work done on the satellite machine into the master branch.
Branch off of a specific tag.
$ git checkout -b private2.6.14 v2.6.14 (1)
$ edit/compile/test; git commit -a
$ git checkout master
$ git cherry-pick v2.6.14..private2.6.14 (2)
1. create a private branch based on a well known (but somewhat behind) tag.
2. forward port all changes in private2.6.14 branch to master branch without a formal "merging". Or longhand git format-patch -k -m --stdout v2.6.14..private2.6.14 | git am -3
-k
安装完毕之后,cmd-s-p shell command install
# 搜索代码的变化
git log -S'<a term in the source>'
# 放弃本地修改,与远程同步
git fetch origin && git reset --hard origin/master && git clean -f -d
# 列出所有冲突文件
git diff --name-only --diff-filter=U
# 手贱错误提交,但是没有 push
git commit -m "Something terribly misguided" (1)
git reset HEAD~ (2)
# edit needing changed files
git add needing changed files (4)
git commit -c ORIG_HEAD (5)
# Delete all changes in the Git repository, but leave unstaged things
git checkout .
# Delete all changes in the Git repository, including untracked files
git clean -f
ChangeLog: