仅显示不影响任何指定路径的提交(Show only commits that don't affect any of the specified paths)

编程入门 行业动态 更新时间:2024-10-15 04:22:55
仅显示不影响任何指定路径的提交(Show only commits that don't affect any of the specified paths)

我正在使用一个分支,我需要分成两个分支:提交触摸指定目录列表中的文件进入一个分支,其余提交进入另一个分支。

现在,我的想法是使用交互式rebase。

要获得第一个分支,我会这样做:

git log --format="pick %h %s" --reverse -- <dir-list>

并将其结果粘贴到为交互式rebase打开的编辑器中。

但是,为了获得第二个分支,我必须为我的仓库中的所有其他目录保持相反的状态。

有没有办法以某种方式获得“对面提交”列表,还是有另一个更容易解决我的问题的方法?

I'm working with a branch that I need to split up in two branches: Commits touching files in a specified list of directories go on one branch, the remaining commits go on the other branch.

Now, my idea was to use interactive rebase for that.

To get the first branch, I'd do this:

git log --format="pick %h %s" --reverse -- <dir-list>

and paste the result of that into the editor opened for the interactive rebase.

But then, to get the second branch, I'd have to maintain the opposite for all the other directories in my repo.

Is there a way to get the list of "opposite commits" somehow, or is there another, easier, solution to my problem?

最满意答案

git log --format="pick %h %s" --reverse -- dir1/ dir2/

可以写

git log --format="pick %h %s" --no-walk \ $(git rev-list --reverse -- dir1/ dir2/)

也就是说,使用

git rev-list HEAD -- dir1/ dir2/

获取“原始”修订ID列表。 现在要获得一组补充的修订ID,我建议像

sort <(git rev-list HEAD) <(git rev-list HEAD -- dir1/ dir2/) | uniq -u

整合一切

互补集将成为

git log --format="pick %h %s" --no-walk \ $(git rev-list --no-walk --reverse \ $(sort <(git rev-list HEAD) \ <(git rev-list HEAD -- dir1/ dir2/) | uniq -u))

注意两者--no-walk在那里没有--no-walk参数,它们是至关重要的

建议

我强烈建议使用bash函数或脚本来实现子步骤 如果您只是想要一种分割存储库的方法,请查看git-filter-branch ! 它将使您能够为每个修订版“掩盖”(删除)树的不需要的部分 允许您跳过有效的空修订,就像您想要的那样 手册页包含了那些样本 如果单个提交编辑了repo的两个部分,它将正常工作 记住--tag-name-filter cat选项 git log --format="pick %h %s" --reverse -- dir1/ dir2/

could be written

git log --format="pick %h %s" --no-walk \ $(git rev-list --reverse -- dir1/ dir2/)

That is, using

git rev-list HEAD -- dir1/ dir2/

to get the list of 'raw' revision ids. Now to get the complementary set of revision ids, I suggest something like

sort <(git rev-list HEAD) <(git rev-list HEAD -- dir1/ dir2/) | uniq -u

Integrating it all

the complementary set would become

git log --format="pick %h %s" --no-walk \ $(git rev-list --no-walk --reverse \ $(sort <(git rev-list HEAD) \ <(git rev-list HEAD -- dir1/ dir2/) | uniq -u))

note both --no-walk parameters there, they are crucial

Recommendations

I highly recommend making bash functions or scripts to implement the substeps here If you are just looking for a way to split repositories, look into git-filter-branch instead! it will enable you 'mask' (remove) the unwanted part of the tree for each revision allows you to skip effectively empty revisions, like you want the man page contains samples for just that it will work (correctly) if a single commit edited both parts of the repo remember the --tag-name-filter cat option

更多推荐

本文发布于:2023-08-01 00:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1351337.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   Show   commits   affect   paths

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!