Git高级操作与实用技巧
1. 代码修改与提交
在开发过程中,我们常常会对代码进行修改。例如,对main.c文件进行如下修改:
+++ b/main.c @@ -1,4 +1,5 @@ #include <stdio.h> +#include <stdlib.h> struct htentry { char *item; @@ -15,6 +16,12 @@ void ht_init(void) int main(int argc, char **argv) { + FILE *f; + + f = fopen(argv[1], "r"); + if (f == 0) + exit(-1); + /* * Print a histogram of words found in a file. * "Words" are any whitespace separated characters.完成修改后,我们需要将这些修改进行提交。首先,使用git add -p命令可以交互式地选择要暂存的修改块。对于“Stage this hunk?”问题,有多种响应选项,如[y,n,q,a,d,/,K,g,e,?],甚至还有延迟处理修改块的选项。另外,还可以使用git add -i命令,它允许我们选择要暂存到索引中的文件路径,之后还能为所选路径选择补丁选项,进入