如果你願意爲此設置一個新的存儲庫,你可以做你想做的。比方說,你有10個提交一個存儲庫:
$ git log --oneline
2c82196 this is commit 10
2bff8eb this is commit 9
7020be2 this is commit 8
0aea964 this is commit 7
c5d5fcb this is commit 6
c80dc97 this is commit 5
591367e this is commit 4
c2524c8 this is commit 3
3aa5e3a this is commit 2
33da02c this is commit 1
你想在提交5.只要運行在整個歷史的互動變基凸顯您的更改:
這將讓你挑名單看起來像:
pick 2d6696b this is commit 1
pick c5c7389 this is commit 2
pick c8cd62d this is commit 3
pick da0fb52 this is commit 4
pick 6ec5fac this is commit 5
pick 7508d6f this is commit 6
pick 6dede0f this is commit 7
pick 9e995b7 this is commit 8
pick 8b1299a this is commit 9
pick 44a32ee this is commit 10
變化pick
到squash
的承諾2-4:
pick 2d6696b this is commit 1
squash c5c7389 this is commit 2
squash c8cd62d this is commit 3
squash da0fb52 this is commit 4
pick 6ec5fac this is commit 5
pick 7508d6f this is commit 6
pick 6dede0f this is commit 7
pick 9e995b7 this is commit 8
pick 8b1299a this is commit 9
pick 44a32ee this is commit 10
...並保存該文件。這將壓扁提交2,3和4到提交一,留給你以下歷史:
$ git log --oneline
9cec0a1 this is commit 10
b39ec3d this is commit 9
3578beb this is commit 8
1ce80b9 this is commit 7
2faaf79 this is commit 6
ff57ad9 this is commit 5
6a53018 this is commit 1
現在承諾5只有一個父母。你可以爲後續的提交做同樣的事情。再次運行:
,然後編輯您的領料單壁球所有後續提交到提交6:
pick 6a53018 this is commit 1
pick ff57ad9 this is commit 5
pick 2faaf79 this is commit 6
squash 1ce80b9 this is commit 7
squash 3578beb this is commit 8
squash b39ec3d this is commit 9
squash 9cec0a1 this is commit 10
這可以讓你:
$ git log --oneline
a7a03ba this is commit 6
01253c9 this is commit 5
a903311 this is commit 1
你可以明顯也只是用來git reset
放棄第5次提交後的所有歷史記錄。
該項目是否已經託管在github/gitlab/etc上?它會是嗎?然後,您只需提供適當的差異網址鏈接... – larsks
它是和可以。但我只是想知道除此之外是否還有其他辦法。看到我上面的編輯。 –
我不知道你的意思是「通過我壓縮A」。如果你想顯示J> I之間的差異,你只關心那些提交之間的差異,你通過鏈接到I.A-H是不相關的。例如,爲了顯示我添加到項目中的功能,我可以直接鏈接到[提交](https://github.com/git/git/commit/f6f2a9e42d14e61429af418d8038aa67049b3821)。 – larsks