Demystify Git

Git虽然很时髦,但是不好学,不好用. 关键是不好理解. 本文用最通俗易懂又直观的方式,帮助大家理解git, git的内部组织, 基本概念,还有常用 的工作流程.

本文来自墙外. "贸易保护主义如同把自己关黑屋子,见不到阳光和空气",但是,和网上长城gfw比起来,那算什么?今天看到一个来自小黑屋外的视频,觉得不错,和大家分享一下。视频地址:https://www.youtube.com/watch?v=GYnOwPl8yCE

Git workflow

1. 简单的,称为github workflow, 一个master线,每个feature 或 developer自己一条线,短命,从master导出,通过github上的 pull request 进行团队合作,比如把feature合并到master 上。github 上有很多团队合作功能和 CI功能。优点:简单。参照:http://scottchacon.com/2011/08/31/github-flow.html

2. 复杂的,称为 git flow,两个以上主线,一个是develop 线(或叫next 线),一个master。 develop线是集成线。所有的features (或称为topic 线) 线从develop导出,合并到此。develop线累积到一定程度后,先分出一条release 线,其名字根据当前的master tag 来定,比如 release-1.2,当稳定到可以发布后,将其合并到master (通常, dev 是master 的超集,所以,这个合并只会包括 fast-forward), 并tag master为 master-1.3。所以 master 其实也是一个release 线,只不它包含最新的哪条release 线。在最新的release线(即master线)上的所有 fix都要合并回dev线,或许也合并到某些较旧的release 线,但是,在较旧的release线上的fix,不一定需要合并到dev线上,因为,dev线上可能已经没有那个feature了。 参照:http://nvie.com/posts/a-successful-git-branching-model/ 。有点:高并行性高,适合大团队,大项目。

Git Squash Method:

1. >git rebase -i HEAD~5 #squash last 4 commit,

edit the file to choose pick or squash

2. make sure index and working tree is clean

>git reset --soft HEAD~5 #head moved, index and working tree untouched

>git commit --edit -m"$(git log --format=%B --reverse HEAD~5..HEAD)"

3. make sure all stuff commited

>git reset --hard HEAD~5

>git merge --squash HEAD@{1} # HEAD@{1} is the previous head before reset --hard

>git commit

Move git branch head around

>git checkout commit  #detached head

>git branch -f branch-name head #glitch: fail if current branch, the previous cmd avoid this.

Diff 控制

在 git diff --no-index 时, .gitignore 等的设置不起作用,有个解救,利用 .gitattributes 文件,例如, *.obj  -diff ,  

*.dll diff=nodiff
and
git config diff.nodiff.command /bin/true
or git config diff.nodiff.command echo

参 git manual gitattributes or config

注意,因为no-index 需要两个path, 所以 pathspec 方法(参git help glossary)不行 。
pathspec 方法例子:path/to/*.* :!*.obj 或等同的:path/to/*.* :(exclude)*.obj

原文地址:https://www.cnblogs.com/kakrat/p/6439413.html