Stash:
# working on branch "master"
git stash
git checkout -b hotfix
# fix the bug
git commit -a
git checkout master
git merge hotfix
git stash apply
# or "git stash pop" if you are confident
查看某文件修改历史:
git log -p filename
将某个版本的某个文件拷贝到/tmp目录:
git show $commitid:$filename > /tmp/$filename
将工作目录的某个文件恢复到当前(master)版本:
git checkout -- $filename
将某个版本的某个文件拷贝到工作目录:
git checkout $commitid $filename
获取与HEAD对应的尾版本号:
git rev-list --max-parents=0 HEAD
git export:
git archive --format zip --output ../scaffold.zip master
查看某commit或之前某commit具体信息:
git show a61bc91
git show a61bc91~1
在历史中搜索commit关键词:
git log --grep keyword
查看远端源路经:
git remote -v
显示两个版本间改动的文件列表:
git diff --name-only rev1 rev2
建立一个可以多人操作的源:
git --bare init --shared=group
或者
git --bare init --shared=0xNNNN
git颜色
git config color.ui always
git config color.ui never
git config color.ui auto
这将在全局范围内启用color.ui(写到~/.gitconfig):
git config --global color.ui always
~/.gitconfig
配置全局user:
[user]
email = yourname@domain.com
name = yourname
回滚中间某个commit:
假设要回滚dd61ab32这个commit,但是要保留之后的所有commit:
git rebase -i dd61ab32^
然后会出现:
pick dd61ab32
pick dsadhj278
...
把要回滚的那行(第一行)删掉(dd),
再保存退出(:wq),
假如有conflict的话手工解决掉,
最后git push -f强制push即可。
获取远端branch:
git checkout -b branch_name origin/branch_name
忽略tags目录
vim ~/.gitconfig
[core]
excludesfile = "path_to/.ignore"
.gitignore内容:
tags
忽略某些文件
git update-index --assume-unchanged log/*
push时远端触发事件:
vi hooks/post-update:
curl http://10.132.64.207:8261/pull.pl
未完待续
