git取兩次提交的文件列表,包含目錄信息


1.用git rev-list HEAD取得版本號列表:

在SmartGit中看到的也是這樣,驗證了我們的猜想:

取到兩個版本號之后,用git diff命令:git diff [--options] <commit>...<commit> [--] [<path>…​]

這里的[-options]我們填的是--name-status,<commit>指的是版本號,也就是每次版本的散列值,可以填前幾位就可以了,git會自動識別。

--name-status選項,可以輸出每個修改的文件的狀態,添加,修改,刪除還是重命名等。

輸入命令git diff --help可以查看幫助文檔:

--name-status
Show only names and status of changed files. See the description of the --diff-filter option on what the status letters mean.
--diff-filter=[(A|C|D|M|R|T|U|X|B)…​[*]]
Select only files that are Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R), have their type (i.e. regular file, symlink, submodule, …​) changed (T), are Unmerged (U), are Unknown (X), or have had their pairing Broken (B). Any combination of the filter characters (including none) can be used. When * (All-or-none) is added to the combination, all paths are selected if there is any file that matches other criteria in the comparison; if there is no file that matches other criteria, nothing is selected.

Also, these upper-case letters can be downcased to exclude. E.g. --diff-filter=ad excludes added and deleted paths.

其中M和1.txt之間是\t,后面的是目錄和文件,如果是在ubuntu下的話,比如修改了文件夾aa下的my.txt

則:

M\taa/my.txt

因為linux上的文件夾目錄都是/,windows的,沒有測試有需要的可以測試。

如何要輸出到文件中:

// >> 后加輸出文件的路徑、文件名和后綴名
 git diff [branchA] [branchB] >>d:/diff/exportname.diff
linux的重定向命令
覆蓋 git diff [branchA] [branchB] > a.txt
追加 git diff [branchA] [branchB] >> a.txt

參考:https://segmentfault.com/q/1010000005033288

命令的具體參考幫助文檔:git diff --help

用git show命令也可以:

git show會在下面包含每個文件的對比信息(內容),這將會是大量字符串。

具體如果有目錄下的文件不能顯示區別,則兩個命令的差異實踐幾次就會發現,可以解決問題的。

參考:http://www.01happy.com/git-extract-different-files/

     http://diannaowa.blog.51cto.com/3219919/1671384


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM