如何在没有完整仓库的情况下理想地展示git中的密钥提交

时间:2017-09-28 12:25:13

标签: git diff

像我们所有人一样,我已经完成了一些关键代码提交,这些提交在遵循SOLID范例,编写良好的算法等方面显示了我的逻辑。我想在类似的界面中展示这一点(并排)你可以在GitLab或GitHub上找到差异。

有没有办法做这个(而不是截图)并不涉及复制整个存储库?在这种情况下,安全性不是问题,客户不会介意或反对,但显然复制整个回购并不是一个好的解决方案。

- 编辑 - 由于可能是GitHub是唯一或最佳解决方案,也许更好的问题或方向可能是这样:

所以master分支提交/合并A到Z.我的合并是J,M和X.我可以压缩A到I,显示J>的合并I,压缩K到L,显示M>的合并。 L等?

1 个答案:

答案 0 :(得分:2)

如果您愿意为此目的设置新的存储库,您可以按照自己的意愿行事。假设您有一个包含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.只需在整个历史记录中运行交互式rebase:

$ git rebase --root -i

这将为您提供一个类似于以下内容的选择列表:

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                                                  

将提交2-4 {<1}}更改为pick

squash

...并保存文件。这会将提交2,3和4压缩为提交1,留下以下历史记录:

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                                                  

现在,commit 5只有一个父级。您可以为后续提交执行相同的操作。再次运行:

$ 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

然后编辑您的选项列表以将所有后续提交压缩到提交6:

$ git rebase --root -i

这会让你:

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 在提交5之后丢弃所有历史记录。