Git 是软件开发过程的记录工具,为了更加准确的定位每个问题、每个功能修改,就需要在每完成一部分可以称得上是“一项”的工作时,就 commit 一次。哪怕只是修改了一两行,只要产生了必要的功能改变,就有价值记录。当采用代码审核机制或者需要用邮件提交补丁时,较小的提交能够更有效、更容易、更准确的被检查和审核。
- 控制好提交粒度。每次的提交都必需具有独立性的原子性,建议是:
- 以一个功能点或 bug fix 为单位;
- 无直接关联的文件不能在同一次提交;
- 如果一个文件修改过多次,添加了很多功能以后,才记起来提交,要使用
$git add -p
对这个文件进行分行提交。对于这个操作建议使用图像化工具,如 GitX,SourceThree 等
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<title></title> | |
<link rel="stylesheet" href=""> | |
<style> | |
.forceGlobalModalIndicator.hidden { |
-
比较两次提交之间的文件,只显示文件名
$ git diff --stat
-
Git cherry-pick 和 rebase 的混合用法
$ git checkout master
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[merge] | |
tool = mymerge | |
[mergetool "mymerge"] | |
cmd = /Applications/p4merge.app/Contents/MacOS/p4merge \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\" | |
trustExitCode = false | |
[mergetool] | |
keepBackup = false |