Skip to content

Commit 72c3e70

Browse files
committed
git diff-tree and git archive
1 parent 661b834 commit 72c3e70

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,6 +1825,63 @@ git show [<options>] [<object>…​]
18251825

18261826
其他更詳細的介紹,請參考 [https://git-scm.com/docs/git-diff](https://git-scm.com/docs/git-diff)
18271827

1828+
## git diff-tree
1829+
1830+
git-diff-tree - Compares the content and mode of blobs found via two tree objects
1831+
1832+
比較兩個 blob (commit) 的差異.
1833+
1834+
文件可參考 [git-diff-tree](https://git-scm.com/docs/git-diff-tree/en)
1835+
1836+
直接看範例
1837+
1838+
```cmd
1839+
git diff-tree -r --no-commit-id --name-status -a --diff-filter=ACDMRT <其中一個commit id> <要比較的commit-id> > changes.txt
1840+
```
1841+
1842+
`-r` 代表 Recurse into sub-trees.
1843+
1844+
`--no-commit-id` This flag suppressed the commit ID output.
1845+
1846+
`--name-status` Show only the name(s) and status of each changed file.
1847+
1848+
`--text` `-a` Treat all files as text.
1849+
1850+
`--diff-filter=[(A|C|D|M|R|T|U|X|B)…​[*]]`
1851+
1852+
Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R),
1853+
1854+
have their type (i.e. regular file, symlink, submodule, …​)
1855+
1856+
changed (T), are Unmerged (U), are Unknown (X),
1857+
1858+
or have had their pairing Broken (B).
1859+
1860+
執行後打開 change.txt 會看到差異的檔案名稱.
1861+
1862+
```text
1863+
M addons/account/i18n/account.pot
1864+
M addons/account/i18n/ar.po
1865+
M addons/account/i18n/az.po
1866+
M addons/account/i18n/be.po
1867+
M addons/account/i18n/bg.po
1868+
M addons/account/i18n/ca.po
1869+
M addons/account/i18n/cs.po
1870+
......
1871+
```
1872+
1873+
## git archive
1874+
1875+
延續上面的例子, 如果想要打包不同的 commit 之間的差異檔案 (不想要整包匯出, 因為太大了, 只想找出差異檔案),
1876+
1877+
這時候可以搭配 archive 指令, 範例如下
1878+
1879+
```cmd
1880+
git archive --format=zip --output=files-diff.zip HEAD $(git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT <其中一個commit id> <要比較的commit-id>)
1881+
```
1882+
1883+
這樣匯出來的 zip, 就是這兩個 commit 之間差異的完整檔案.
1884+
18281885
## git grep
18291886

18301887
以下為官方說明

0 commit comments

Comments
 (0)