读懂diff的输出

来源:互联网 发布:js window.url 编辑:程序博客网 时间:2024/06/05 03:48

  • 创建git文件的不同
  • 分析git diff的输出

今天在学习git的使用时,用到 git diff 去查看git仓库改变情况,其中关于 diff 的输出,一大堆东西,不知所云,因此,查找相关资料,总结下 diff的输出。

创建git文件的不同

  • 前提:有git仓库
## 在git仓库中编辑一新的文件diff.txt用来做实验,随便添 加一些内容,我这里的内容也是一首英文歌的歌词;[root@foundation16 learngit]# vim diff.txt[root@foundation16 learngit]# cat diff.txthello worldthis is a git diff testSome dreams is big,some dreams are smallsome dreams are carried away on the wind and never dreamed at all.## 添加了文件后要记得把diff.txt文件添加到git仓库中,然后添加说明并提交;[root@foundation16 learngit]# git add  diff.txt[root@foundation16 learngit]# git commit  -m "add diff.txt"[master a4297ec] add diff.txt 1 file changed, 5 insertions(+) create mode 100644 diff.txt## 现在提交完成之后,没有需要更新的内容,这个时候我重新 编辑文件diff.txt,作出响应的修改,为后面分析git diff的输出做准备;[root@foundation16 learngit]# vim diff.txtSome dreams is big,some dreams are smallsome dreams are carried away on the wind and never dreamed at all.some dreams tell lies,some dreams come true.

分析git diff的输出

  • diff的输出结果表明需要对源文件做怎样的操作之后才能与目标文件文件相匹配。
[root@foundation16 learngit]# git diffdiff --git a/diff.txt b/diff.txtindex b83fe1d..59b810c 100644--- a/diff.txt+++ b/diff.txt@@ -1,5 +1,3 @@-hello world-this is a git diff test Some dreams is big,some dreams are small some dreams are carried away on the wind and never dreamed at all.-+some dreams tell lies,some dreams come true.## git diff实质上用的是diff的文本比较工具,其中a/diff.txt代表比较的源文件,b/diff.txt时比较的目标文件;## ---代表源文件,+++代表目标文件;## @@ -1,5 +1,3 @@是差异小结,代表的意思是源文件的1-5行与目标文件的1-3行有差异,下面才是具体的差异信息;## 以空格开头的行代表源文件与目标文件没有差异,以-开头 的行代表在源文件的基础上删除,以+开头代表在源文件基础上添加;

参考资料: http://blog.csdn.net/joe_007/article/details/8674168

原创粉丝点击