-
Notifications
You must be signed in to change notification settings - Fork 2
git
William Zhang edited this page Jan 16, 2019
·
2 revisions
http://www.cheat-sheets.org/#Git
$ sudo yum install git-web $ git gui ...
$ sudo yum install gitk $ gitk
$ sudo yum install gitweb $ man gitweb $ sudo yum install lighttpd $ cd ~/github/misc $ git instaweb
http://git-scm.com/book/
$ 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
$ git log --merges
$ git log | more
再做diff
$ git diff <hash> HEAD
先找到文件的修改历史
$ 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.
$ git reset --hard HEAD~1 The HEAD~1 means the commit before head.
$ 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
git revert <hash> git reset HEAD Makefile
https://mirrors.edge.kernel.org/pub/software/scm/git/docs/gitattributes.html
From a clean working directory:
$ echo "* text=auto" >.gitattributes $ git add --renormalize . $ git status # Show files that will be normalized $ git commit -m "Introduce end-of-line normalization"
- Update .gitattributes with *.cpp filter=codeformat:
# All MySQL code is auto-formatted using clang-format. *.c filter=codeformat *.cc filter=codeformat *.cpp filter=codeformat *.h filter=codeformat *.hpp filter=codeformat *.i filter=codeformat *.ic filter=codeformat
- git config
$ cat .gitconfig ... [filter "codeformat"] <tab>clean = clang-format --assume-filename=%f --style=file [merge] <tab>renormalize = true
- MySQL’s .gitconfig says:
# To automatically add this to your git config so that “git add” and # “git merge” automatically run clang-format, use # # git config --local include.path ../.gitconfig
But, for submodules, it doesn’t work. Can add the contents of .gitconfig above into:
$topdir/.git/modules/<module-name>/config
git config --local filter.codeformat.clean 'clang-format --assume-filename=%f --style=file' git config --local filter.codeformat.smudge 'clang-format --assume-filename=%f --style=file'
Created by Wenliang Zhang.