git小技巧,gitignore只忽略当前目录下的某文件等等

#. 编写git的gitignore文件时如何只忽略当前目录下的某文件呢 在文件名前加斜线 / 即可 # git pull如何从remote中拉下来所有分支 git pull –all git branch -a 查看目前所有分支,包括tracking branch 再用 git branch –track branch_name start_point 开一个本地分支,并且设好该本地分支的upstream # git 10小时免输git密码 git config --global credential.helper "cache --timeout=36000" 如果需要清空存下来的密码: ...

July 28, 2014 · 1 min · kamus

Git 的M,T,D,A,U标志是什么意思

在使用git checkout , git status,或git diff files时会出现奇怪的标志。如M,T,D,A,R,U等等。 如: # git checkout master M     cpp-iniparser 文件cpp-iniparser前面有个M. git的这些奇怪标志是什么意思呢。 A: 增加的文件. C: 文件的一个新拷贝. D: 删除的一个文件. M: 文件的内容或者mode被修改了. R: 文件名被修改了。 T: 文件的类型被修改了。 U: 文件没有被合并(你需要完成合并才能进行提交) X: 未知状态。(很可能是遇到git的bug了,你可以向git提交bug report) 在git diff-files的手册man git diff-files中可以查到这些标志的说明。 这些状态标志在git的源代码的diff.h文件中被定义。 copyright ykyi.net

January 17, 2014 · 1 min · kamus

使用Git的submodule功能管理第三方库

用Git的Submodule功能来管理代码中使用的其它库,还是满方便的。主要用到三个命令: Git submodule add, git submodule init, git submodule update. git submodule init to initialize your local configuration file and git submodule update to fetch all the data from that project and check out the appropriate commit listed in your superproject. 还有两个查看相关信息的命令git submodule summary,和 git submodule status. Git的submodule功能带来的好处和坏处都很多,网上有大量的贴子反对使用git submodule。 我觉有限制地,在以下场景用git submodule管理第三方库的代码还是很不错。 1.    你使用的第三方库更新非常慢,甚至不更新,它的接口很稳定。比如:管理vim的插件们。 2.    第三方库以比较固定的周期更新。于是,过一段时间再把上游的代码拉到submodule上来。 3.    第三方库虽然更新很快,但我过一段时间才拉取上游代码也无所谓。 如果单开一个git clone管理第三方库,与自己的项目平行,当然也是可以的。但这样有个问题是,别人git clone了你的项目,还需要再git clone一次你的项目依赖的项目,并放在适当的相对路径上。而使用git submodule *时,你的项目和你依赖的库是层级关系,有条理得多。   还有一种方式是把第三方库的代码合并到自己的代码中。这样做的坏处是显而易见的,如果你要合并上游代码的FIX或功能加强,都非常的麻烦。大多数人是不会去做这个同步的,于是代码会被手动复制,越来越多的细微改动分散在各个不同的项目的相同/相近代码中。一片混乱…. 使用Git Submodule时忽略Submodule的改动: 如果submodule中有生成新文件。在父工程(superproject)中用git status,就总会提醒你git submodule子模块有还没被跟踪的文件。 比如:一次make会生成很多.o,.dep文件。比如用git submodule管理vim插件会生成各种临时文件。你不想让git status提醒你,这多么烦人啊。 如下,git status总提醒我cpp-iniparser子模块有未跟踪的文件: root@vicarious:/home/kamus/projs/horoscope# git status # On branch dev # Changes not staged for commit: #   (use "git add …" to update what will be committed) #   (use "git checkout — …" to discard changes in working directory) #   (commit or discard the untracked or modified content in submodules) # #    modified:   configuration.cpp #    modified:   configuration.h #    modified:   cpp-iniparser (untracked content) ...

January 16, 2014 · 2 min · kamus

设置变量GIT_CURL_VERBOSE可以帮助调试git出错

今天操作git的时候又出错了: error: Failed connect to github.com:8080; No route to host while accessing https://github.com/zausiu/gryphon/info/refs fatal: HTTP request failed 之前用公司的http代理上git, #git config -l http.proxy=http://web-proxy.oa.com:8080 设置变量GIT_CURL_VERBOSE可以看到详细的出错情况: #export GIT_CURL_VERBOSE=1 # git pull Couldn’t find host github.com in the .netrc file; using defaults About to connect() to proxy web-proxy.oa.com port 8080 (#0) Trying 10.14.36.100… 0x23d67b0 is at send pipe head! STATE: CONNECT => WAITCONNECT handle 0x23df5f0; (connection #0) No route to host Failed connect to github.com:8080; No route to host Closing connection #0 Couldn’t find host github.com in the .netrc file; using defaults About to connect() to proxy web-proxy.oa.com port 8080 (#0) Trying 10.14.36.100… 0x23d67b0 is at send pipe head! STATE: CONNECT => WAITCONNECT handle 0x23df5f0; (connection #0) No route to host Failed connect to github.com:8080; No route to host Closing connection #0 error: Failed connect to github.com:8080; No route to host while accessing https://github.com/zausiu/gryphon/info/refs fatal: HTTP request failed copyright ykyi.net ...

November 27, 2013 · 1 min · kamus

为什么我的名字没有出现在github的contributor列表中.

为什么我没有出现在github.com的contributor列表中. 我提交了commit,但为什么我没有出现在贡献者列表中呢。有三个原因: 1. 检查你的commit中的邮箱信息,这个邮箱必须和你的github.com账号关联。怎么关联邮箱账号呢。先选择Account Setting, 在左边先Emails,于是就看到可以verify邮箱地址的页面了。关联邮箱地址后还有过一段时间,贡献者列表才会更新。 2. 如果工程的贡献者名单列表超过了100个。就不会显示100个以后的贡献者了。官方HELP中说这是为了性能的考量。我觉得是码农偷懒,必竟这个需求太小了。绝大多数工程不会超过100个贡献者,于是码农不想解决这个小问题。 3. 你的commit必须被提交到工程的默认分支上。如果提交到其它的分支上,你的名字就不会被显示。 为什么我没有出现在github.com的contributor列表中. 我提交了commit,但为什么我没有出现在贡献者列表中呢。有三个原因: 1. 检查你的commit中的邮箱信息,这个邮箱必须和你的github.com账号关联。怎么关联邮箱账号呢。先选择Account Setting, 在左边先Emails,于是就看到可以verify邮箱地址的页面了。关联邮箱地址后还有过一段时间,贡献者列表才会更新。 2. 如果工程的贡献者名单列表超过了100个。就不会显示100个以后的贡献者了。官方HELP中说这是为了性能的考量。我觉得是码农偷懒,必竟这个需求太小了。绝大多数工程不会超过100个贡献者,于是码农不想解决这个小问题。 3. 你的commit必须被提交到工程的默认分支上。如果提交到其它的分支上,你的名字就不会被显示。   copyright ykyi.net      

November 20, 2013 · 1 min · kamus

如何删掉github上的master分枝.

假设,代码已经被clone到了本地。第一步要做的就是创建一个新的分支,比如placeholder,然后用-D从本地删除master分支。 git branch placeholder git checkout placeholder git branch -D master 如果现在删除github上的master,会报错: ...

November 1, 2013 · 1 min · kamus

git的排错神器pickaxe和git blame

git log -Sstring 这里的-S选项被称作pickaxe,这是一个非常好的排错工具。 比如: git log -Sinclude –pretty=oneline –abbrev-commit init/version.c 会把减少了,或者增加了include的commit全部找出来。 要注意的是,如果有一个提交增加和减少include的次数一样,这个commit不会被列出来。 ///////////// 另外一个排错工作是 git blame: git blame可以用来帮助查找引入bug的commit。git blame告诉你谁,什么时候,是哪个commit更改了某个文件。 如: git blame -L 32, init/version.c

January 29, 2013 · 1 min · kamus

knowledge gained from learning git.

# If you inadvertently remove a file of your working copy. Don’t worry. Git are good at recovering old versions of files, such as: $git checkout HEAD — data # show what the file looks like in a certain branch. $git show branch_name:file_name # In newer versions of Git, git diff –ours is a synonym for git diff HEAD, because it shows the differences between “our” version and the merged version. Similarly, git diff MERGE_HEAD can be written as git diff –theirs. You can use git diff –base to see the combined set of changes since the merge base, which would otherwise be rather awkwardly written as: git diff $(git merge-base HEAD MERGE_HEAD) ...

September 9, 2011 · 3 min · kamus