如何显示部分或全部文件之间的差异? GIT [英] how to show differences betwen some or all files? GIT

查看:100
本文介绍了如何显示部分或全部文件之间的差异? GIT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在主题中:如何显示部分或全部文件之间的差异?



对不起,我搞砸了我的问题。我的意思是一个或多个或所有文件的分支之间的差异。

b
$ b

  git diff< commit1> < commit2> -  path / to / file.cpp path / to / anotherfile.cpp path / to / subdir 

你也可以(例如bash)

$ g $ diff git diff {commit1>,< commit2>}:path / to / file.cpp

这样你甚至可以

  git diff< commit1>:path / to / file.cpp< commit2>:path / to / anotherfile.cpp 
pre>

这是非常强大的,恕我直言。


$ b

替换< commit1> < commit2> 通过任何名称的标签,分支(本地或远程)或直接sha1提交的散列(这被称为 commit-ish

<要获得真正的时髦,你可以指定tree-ish或blob哈希。

  $ git ls-tree HEAD ^ | grep blob | sort -R |头-2 
100644团块27785581e788049ac805fab1d75744dd7379735d的.gitignore
100644团块2821a5271ffd8e6b11bb26b8571f57e88ab81f38 TESTING

$ git的差异--stat 2821a5271ffd8e6b11bb26b8571f57e88ab81f38 aa96765714a3058068c4425d801fab4b64e26066
... F38 => aa96765714a3058068c4425d801fab4b64e26066 | 155 +++++++++++++++++ ---
1个文件已更改,135个插入(+),20个删除( - )

现在你通常不会这样做,除非你在repo中有多个版本的'same'文件(这是不确定的,如果你问我)。


As in the subject: how to show differences betwen some or all files?

Sorry i've screwed up my question. I meant differences betwen branches for one or multiple or all files.

解决方案

Or perhaps a bit more helpful:

git diff <commit1> <commit2> -- path/to/file.cpp path/to/anotherfile.cpp path/to/subdir

You can also (in e.g. bash)

git diff {<commit1>,<commit2>}:path/to/file.cpp

This way you can even

git diff <commit1>:path/to/file.cpp <commit2>:path/to/anotherfile.cpp

which is quite insane powerful, IMHO.

Replace <commit1> and <commit2> by any name of tag, branch (local or remote) or direct sha1 hash of a commit (this is known as a commit-ish)

To get really funky, you can specify tree-ish or blob hashes if you want. Do something completely silly with this for a sample:

$ git ls-tree HEAD^ | grep blob | sort -R | head -2
100644 blob 27785581e788049ac805fab1d75744dd7379735d    .gitignore
100644 blob 2821a5271ffd8e6b11bb26b8571f57e88ab81f38    TESTING

$ git diff --stat 2821a5271ffd8e6b11bb26b8571f57e88ab81f38 aa96765714a3058068c4425d801fab4b64e26066
 ...f38 => aa96765714a3058068c4425d801fab4b64e26066 |  155 +++++++++++++++++---
 1 files changed, 135 insertions(+), 20 deletions(-)

Now you won't usually do this, unless you have several versions of the 'same' file in you repo (which is iffy, if you ask me).

这篇关于如何显示部分或全部文件之间的差异? GIT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆