http://jonas.iki.fi/git_guides/ The Git Guides
http://wiki.laptop.org/go/Git_Tips git技巧集
http://marc.info/?l=git 有很多git相关的问答
http://www.kernel.org/pub/software/scm/git/docs/user-manual.html 用户手册
http://git.or.cz/gitwiki/GitTips Git小技巧
http://utsl.gen.nz/talks/git-svn/intro.html#feature-branches git-svn好资料
http://bazaar-vcs.org/BzrVsGit Bzr与Git的比较
http://www.dont-panic.cc/capi/?s=git
为什么说 Git 将取代 SVN 做软件版本控制? http://www.javaeye.com/news/4503-tortoisegit-windows-user-to-use-git tortoisegit: Windows用户使用Git的福音
http://rubynroll.javaeye.com/blog/203133
SVN+GIT=鱼与熊掌兼得 http://docs.google.com/View?id=dfwthj68_675gz3bw8kj
Git 魔法 [文章推荐]Comparison of revision control software http://en.wikipedia.org/wiki/Comparison_of_revision_control_software
$ git commit --amend http://cworth.org/hgbook-git/tour/ 中有介绍,
好像是可修改前一次提交的msg
$ git stash save "some message" 当遇到一个小BUG但又不想马上解决,要等到你过段时间才解决的时候
$ git stash list
$ git stash apply [--index] [<stash>] (恢复状态)
$ git stash clear (clear all)
$ git stash
drop [stash ] (clean one)
$ git stash
pop [stash ] (clean one and apply)
[am = apply mail]
$ git am -3 patches.mbox
$ git fetch origin todo:my-todo-work
$ git fetch git://example.com/proj.git master:example-master
从origin仓库中将提取出来的master分支放到新创建的example-master分支中,相当于新建一个分支代替master
$ git count-objectsRecovering from repository corruption$ git-fsck --full
$ git log SHA1 --> SHA1 只要hexdig的前6-8个就行了
7.错误提交了commit怎么办?
a) git-revert
这个本身就会产生一个commit,如果用得多了会让你的log看起来不那么干净。;-)
b) git-reset
用这个要当心,它会把那个commit之后的commit全部删除。一个好的办法是:先建立一个临时的分支,然后再git-reset,再git-rebase,最后再删除临时的分支。 详细可以看这里。
$ git commit --amend 修订上一次提交的msg
$ git commit -s --amend
< >-s, --signoff add Signed-off-by: header
--amend amend previous commitHow to change commits deeper in history git rebase --onto <tmp branch> <commit after changed> <branch>.
git filter-branch can also be usefull. It has been ported from the obsoleted Cogito's .How to get only merges in gitk?gitk --full-history -- a//b
What to do if you have realized that you are on wrong branch?git checkout -m <correct-branch> -m merge local modifications into the new branchRecovering lost changes
$ git log master@{1}
$ git show master@{2} # See where the branch pointed 2,
$ git show master@{3} # 3, ... changes ago.
$ gitk master@{yesterday} # See where it pointed yesterday,
$ gitk master@{"1 week ago"} # ... or last week
$ git log --walk-reflogs master # show reflog entries for master
$ git show HEAD@{"1 week ago"} #=======================================================================
在工作目录下修改 .gitignore 来ingore一些文件 如 src/*.bak tmp/*
git config --global color.diff auto
git config --global color.status auto
git config --global color.branch auto
git config --global branch.autosetupmerge auto
git config --global user.name "Your Name Comes Here"
git config --global user.email
[email protected]
git apply patch -p0 相当于打补丁 git-format-patch 生成补丁
git pull svn update
git-revert(1) to undo botched commits. 与svn的revert不同,如想达到svn效果用 reset
$ git-checkout -f foo.c 这招强制覆盖
$ git fetch /home/bob/myrepo master:bob-incoming
这个命令将 Bob 的 master 分支的导入到名为 bob-incoming 的分支中( 不同于 git-pull 命令,git-fetch 命令只是取得 Bob 的开发工作的拷贝, 而不是合并经来)。接着:
$ git whatchanged -p master..bob-incoming
$ git repack 打包 $ git prune-packed 清除已打包后多余的东东 对比查看.git/object目录下的内容 find .git/objects -type f
$ git branch -D branch-name (delete branch)
$ git whatchanged
$ git checkout -b new v2.6.13 从v2.6.13版出中创建一个new分支开始work
$ git branch -r 其中-r 是remote的意思,如果带有 -d xx表示删除远程的branch
$ git checkout -b my-todo-copy origin/todo
Note that the name "origin" is just the name that git uses by default to refer to the repository that you cloned from.
$ git add -X "*.bak" .
$ git show HEAD^:path/to/file
$ git am --resolved
$ git clone --bare ~/proj proj.git 制作共享仓库
$ touch proj.git/git-daemon-export-okExporting a git repository via http$ mv proj.git /home/you/public_html/proj.git
$ cd proj.git
$ git --bare update-server-info
$ chmod a+x hooks/post-update
$ git push ssh://yourserver.com/~you/proj.git master:master
$ cat >>.git/config <<EOF
[remote "public-repo"]
url = ssh://yourserver.com/~you/proj.git
EOF
$ git push public-repo master
$ git-cat-file blob|tree|commit|tag <objectname>
$ git branch -r 列出远端仓库中的分支
$ git fetch origin
Publishing changes
$ git push origin mybranch:myuserid
If you have created tags that you want to make public you need to push them explicitly
$ git push --tags origin
$ git push origin <branch>:refs/heads/<branch> Creating remote branches
$ git push origin :<branch> Deleting remote branches and tags
To delete a tag on the master you need to explicitly push an empty tag
$ git push origin :refs/tags/<tag>
Cleaning up
$ git remote prune
$ git branch -d -r <remote>/<branch>git-pushcp from -- zhllg
一直没用过git-push,原来以为git-push会像git-pull一样调用git-merge
不过,我忘记了,git repo只是一个.git目录而已,没有实际项目文件在里面
顺便改了改现有的几个git repo的地址
http://www.gentoo-cn.org/gitweb/
<1>用git-checkout HEAD^2 foo.c 恢复用 checkout HEAD foo.c 会有提示,用 -f搞定
<2> git-push 会提交到远程仓库,但不会自动调用git-merge来解决,所以远程仓库用户 checkout的话才能发现冲突
<3> 如用查看 reset --hard HEAD^2 ==>> reset --hard HEAD@{1}
<4> man git-rev-parse会有树状的图表示 isa-^n 表示回退n isa~n 中的n表示n个 ^1 , ^HEAD 表示排除
<5>git-fetch -v 相当于update远程数据到本地来,相当于svn update --> git-pull 才更新数据到本地,才发现对比有数据变更,还要再学学
<6> git-log --color git-branch --color
<7>git-branch $USER/work 可以生成像目录树一样的branch ,也可以同样方法生成tag, git-tag $USER/mytag , 在生成 brahcn or tag可以 branch mybranch master^2 ==>表示基于master^2来生成分支,同理可用于tag
<8> git fetch origin --> origin表示远程clone的仓库, git-merge origin/master 表示将远程的master分支内容merge到本地当前分支, 另一招 git-branch foobar origin/foobar $git-checkout foobar就相当于origin/foobar,方便
<9>git-push origin myLocalBranch:RemoteExistBranch 提交, 如果已创建了tags的话可以$git-push --tags origin
<10> $git-push origin <mySrcBranch>:refs/heads/<destRemoteBranch> 在本地仓库向远程创建一个新分支, :refs这种语法采用 .git/refs目录这种结构
<11>git-push origin :<RemoteBranch> 清除远程分支,注意,前面的: 前没有是空的 , $git-push origin :refs/tags/<remoteTag>清tag
<12>清理 $git-remote prune $git-branch -d (delete) -r (remote) <remote/RemoteBranch> 清掉远程的RemoteBranch分支
<13>git-checkout -b work 自动创建一个work分支并checkout过去
<14>$git-whatchanged -p $git-checkout HEAD~7 foobar.c $git-show HEAD~7:foobar.c >foobar~7.c
<15>git-format-patch 生成补丁,默认用的是-2 ,可以设置为-3
<16>$git-stash 很有用,
<17> $git-repack $git-prune $git-gc --prune --aggressive 清查仓库
<18>git checkout -m <correct-branch>
<19>git rebase --onto <current> <master> <tmpBranch>
<20> 比较两个本地仓库GIT_ALTERNATE_OBJECT_DIRECTORIES=../repo/.git/objects git-diff-tree $(GIT_DIR=../repo/.git git rev-parse --verify HEAD) HEAD
方法2:GIT_ALTERNATE_OBJECT_DIRECTORIES=../repo/.git/objects cg-diff -r `GIT_DIR=../repo/.git cg-object-id -c HEAD`..HEAD
<21>How to remove all files which are missing from working directory?$git ls-files -z --deleted | git update-index -z --remove --stdin<22>$ git ls-files -o --exclude-standard >> .gitignore
<23>
$ cat >>.git/config <<EOF
[remote "public-repo"]
url = ssh://yourserver.com/~you/proj.git
EOF
$ git push public-repo master
<24> $ git push ssh://yourserver.com/~you/proj.git +master
Forcing git fetch to do non-fast-forward updates
If git fetch fails because the new head of a branch is not a descendant of the old head, you may force the update with:
$ git fetch git://example.com/proj.git +master:refs/remotes/example/master
Note the addition of the "+" sign. Alternatively, you can use the "-f" flag to force updates of all the fetched branches, as in:
$ git fetch -f origin
Be aware that commits that the old version of example/master pointed at may be lost, as we saw in the previous section
<25>$ git name-rev --tags e05db0fd
e05db0fd tags/v1.5.0-rc1^0~23
$ git describe e05db0fd
v1.5.0-rc0-260-ge05db0f 反向查询
$ git merge-base e05db0fd v1.5.0-rc1
e05db0fd4f31dde7005f075a84f96b360d05984b
$ git show-ref --heads
Undoing a merge
If you get stuck and decide to just give up and throw the whole mess away, you can always return to the pre-merge state with
$ git reset --hard HEAD
Or, if you've already committed the merge that you want to throw away,
$ git reset --hard ORIG_HEAD
Merging multiple trees$ git-merge-base <commit1> <commit2>
$ git rebase -i HEAD~5
$ git show v2.5:fs/locks.c 查找指定老版本
$ git-clone --bare xxxx_repos clone_repos ==>> 一个只有仓库的clone #=======================================================================
$ ls .git/objects/??/*
$ git-diff-files -p
$ git-diff-index -p HEAD
$ git-diff-tree -p HEAD
$ cg-tag-ls v1.0 很方便地列出tag信息
$ git checkout -b mybranch 创建并跳转到分支
$ git checkout mybranch 切换分支
$ cg-status -g
$ git branch <branchname> [startingpoint]
$ git-show-branch --topo-order --more=1
#=========================================================================
$ git config remote.linus.url http://www.kernel.org/pub/scm/git/git.git/
and use the "linus" keyword with git pull instead of the full URL.
Examples.
1.
git pull linus
2.
git pull linus tag v0.99.1
the above are equivalent to:
1.
git pull http://www.kernel.org/pub/scm/git/git.git/ HEAD
2.
git pull http://www.kernel.org/pub/scm/git/git.git/ tag v0.99.1
#=========================================================================
$ git-name-rev $mb ==> --all
$ git-ls-files --stage
$ git-ls-files -t
$ git-ls-files --unmerged
关于gitweb的配置,大概是这样的步骤
emerge gitweb
git-clone 我的3个git repo http://www.gentoo-cn.org/gitweb/
clone在htdocs下某个目录里即可
然后在/var/git里建立几个符号链接,这是我的:
zhangle@loongson /var/git $ ls -l
总计 0
lrwxrwxrwx 1 root root 28 08-27 00:47 gentoo-cn -> ../www/localhost/htdocs/.git
lrwxrwxrwx 1 root root 31 08-27 00:52 gwn-cn -> ../www/localhost/htdocs/gwn.git
lrwxrwxrwx 1 root root 46 10-18 12:21 loongson ->
../www/localhost/htdocs/loongson-overlay/.git/
为了显示出正确的owner,就像这里 http://www.gentoo-cn.org/gitweb/
需要 useradd -m -C "Zhang Le" zhangle
然后把所有的git仓库文件的所有者改成zhangle
为了显示正确的cloneurl,就像这里 的
URL git-clone http://www.gentoo-cn.org/.git
要在.git目录下建一个cloneurl文件,比如:
zhangle@loongson /var/git/gentoo-cn $ ls
cloneurl description HEAD index logs ORIG_HEAD RENAMED-REF
config FETCH_HEAD hooks info objects refs
zhangle@loongson /var/git/gentoo-cn $ cat cloneurl
git-clone http://www.gentoo-cn.org/.git
我知道的差不多就是这么多
附件里是我的cgiirc的配置文件
/var/www/localhost/cgi-bin/cgiirc-0.5.9/cgiirc.config
(1)Create a remote branch
git clone git+ssh://dev.laptop.org/git/sugar
cd sugar
git branch update-1
git push origin update-1
(2)Work on a remote branch
git clone git+ssh://dev.laptop.org/git/sugar
git checkout --track -b update-1 origin/update-1
git pull
(3)You can now use commit, push and pull as usual. Apply changes from master
git-cherry-pick <commit-id>
git push
(4) Reverting changes
When you mess up a file and want it back to what it was, cd into the directory and:
git checkout HEAD -- gridwidget.py
To remove uncommitted changes and reset the project to HEAD:
get reset --hard HEAD
(5) When you want an activity that sugar-jhbuild does not bring down
Read only:
git-clone git://dev.laptop.org/projects/tamtam
If you have commit access:
git-clone git+ssh://dev.laptop.org/git/projects/tamtam
$git-annotate -b file 查看注释
使用gitweb, 将lighttpd.conf加入
#============================================
server.indexfiles += ("gitweb.cgi")
cgi.assign = ( ".pl" => "/usr/bin/perl",".cgi" => "/usr/bin/perl" )
#============================================
之前
cgi.assign = ( ".pl" => "/usr/bin/perl",".cgi" => "/usr/bin/perl" ) #中的.cgi指向没设置好导致房问失败
建议 /var/git目录,将git的仓库ln -sv 过去就行了,注意拷备gitweb目录时有个.htaccess文件也要拷过去
创建 .git/cloneurl 文件,写入 git-clone git://myip/my.git 以便显示
修改 .git/description加上自己的描述信息