如何在没有完整仓库的情况下理想地展示 git 中的关键提交
How to showcase key commits in git ideally without a full repo
像我们所有人一样,我已经完成了一些关键代码提交,这些代码显示了我遵循 SOLID
范式、编写良好的算法等的逻辑。我想在类似的界面中展示它(并排)差异,如您在 GitLab 或 GitHub.
上所见
有没有不涉及复制整个存储库的方法(而不是屏幕截图)?在这种情况下,安全不是问题,客户不会介意或反对,但显然复制整个 repo 不是一个好的解决方案。
-- 编辑--
由于 GitHub 可能是唯一或最佳解决方案,也许更好的问题或方向可能是这样的:
所以 master
分支有 commits/merges A 到 Z。我的合并是 J、M 和 X。我可以通过 I 压缩 A,显示 J > I 的合并,通过 L 压缩 K , 显示 M > L 等的合并?
如果您愿意为此目的建立一个新的存储库,您可以随心所欲。假设您有一个包含 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 中突出显示您的更改。只是 运行 整个历史记录的交互式变基:
$ 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 的 pick
更改为 squash
:
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 压缩为提交 1,留下以下历史记录:
$ 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 只有一个父级。您可以为后续提交做同样的事情。再次 运行:
$ git rebase --root -i
然后编辑您的选择列表以将所有后续提交压缩到提交 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 后的所有历史记录。
像我们所有人一样,我已经完成了一些关键代码提交,这些代码显示了我遵循 SOLID
范式、编写良好的算法等的逻辑。我想在类似的界面中展示它(并排)差异,如您在 GitLab 或 GitHub.
有没有不涉及复制整个存储库的方法(而不是屏幕截图)?在这种情况下,安全不是问题,客户不会介意或反对,但显然复制整个 repo 不是一个好的解决方案。
-- 编辑-- 由于 GitHub 可能是唯一或最佳解决方案,也许更好的问题或方向可能是这样的:
所以 master
分支有 commits/merges A 到 Z。我的合并是 J、M 和 X。我可以通过 I 压缩 A,显示 J > I 的合并,通过 L 压缩 K , 显示 M > L 等的合并?
如果您愿意为此目的建立一个新的存储库,您可以随心所欲。假设您有一个包含 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 中突出显示您的更改。只是 运行 整个历史记录的交互式变基:
$ 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 的 pick
更改为 squash
:
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 压缩为提交 1,留下以下历史记录:
$ 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 只有一个父级。您可以为后续提交做同样的事情。再次 运行:
$ git rebase --root -i
然后编辑您的选择列表以将所有后续提交压缩到提交 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 后的所有历史记录。