Skip to content
William Zhang edited this page May 11, 2017 · 2 revisions

Git

http://www.cheat-sheets.org/#Git

git-gui

$ sudo yum install git-web
$ git gui ...

gitk

$ sudo yum install gitk
$ gitk

gitweb

$ sudo yum install gitweb
$ man gitweb
$ sudo yum install lighttpd
$ cd ~/github/misc
$ git instaweb

http://git-scm.com/book/

branch

$ git checkout -b dev-review origin/dev
$ git branch <your branch> // Switch to branch
$ git pull origin master // Sync master changes inside your branch
$ git diff --name-only master <branch> // List of the changed files

log

$ git log --merges

diff

怎么diff当前branch与它的parent(以找出当前branch的所有改动。先找到它的parent的最后一次提交对应的hash值。

$ git log | more 

再做diff

$ git diff <hash> HEAD

怎么diff给定文件的两个版本

先找到文件的修改历史

$ git log sql/sys_vars.cc

从中找到两个待比较的hash值,再开始比较

$ git diff hash1 hash2 -- sql/sys_vars.cc

** 在有未决冲突时,怎么回滚掉这些未决的文件?

例如:
#+NAME: <s>
$ git checkout master
sql/field.cc: needs merge
sql/sql_show.cc: needs merge
sql/sql_show.h: needs merge
sql/sql_yacc.yy: needs merge
error: you need to resolve your current index first
$ git reset --merge

删除未受控的本地代码

$ git clean -f
But beware... there's no going back. Use -n or --dry-run to preview the damage you'll do.

撤销最近的一个commit

$ git reset --hard HEAD~1
The HEAD~1 means the commit before head.

撤销到指定的一个commit

$ git reset --hard <sha1-commit-id>
  • 如果已经提交到了远程,则还需要push一下

If you already pushed it, you will need to do a force push to get rid of it…

$ git push origin HEAD --force

rollback

git revert <hash> git reset HEAD Makefile

Clone this wiki locally