简体   繁体   English

如何从'git filter-branch'获取old-> new重写提交SHA的列表?

[英]How do I get a list of old->new rewritten commit SHAs from 'git filter-branch'?

After running git filter-branch , how do I get a list of old commit SHAs as rewritten by filter-branch to their new corresponding commit SHAs? 在运行git filter-branch ,如何获得由filter-branch重写为新的相应提交SHA的旧提交SHA列表?

For example, something similar to: 例如,类似于:

b19fd985746c1f060f761d42d353e387bec243fb -> c8ab40ef9bae3b58642a8d1e5b90720d093a60b5
c5ebba1eeb92ca76c0effa32de14178ec7f07db6 -> 4d5a9958b98dbcfa47ce1354bb2af4cc77904639
705f71543235b872ca3e1067538e36d14044429d -> d2aafbd6e5b91955b62dee34f4a0abf0171ba016

Where the left column is the list of original SHAs, and the right column are the new SHAs after being rewritten by filter-branch. 左列是原始SHA的列表,右列是filter-branch重写后的新SHA。

I see that the man page for filter-branch mentions a map function, but I don't understand whether that's useful here, or if it is, how to use it. 我看到filter-branch的手册页提到了一个map函数,但是我不明白这里是否有用,或者它是否有用,如何使用它。

Thanks for your help! 谢谢你的帮助!

I had to go poking around the source for git-filter-branch to work this one out. 我不得不去寻找git-filter-branch的源代码来解决这个问题。 It's not documented (as far as I can tell), but the old commit ID is explicitly exported as $GIT_COMMIT . 它没有记录(据我所知),但旧的提交ID显式导出为$GIT_COMMIT This worked for me: 这对我有用:

$ git filter-branch --your-filters-here --commit-filter 'echo -n "${GIT_COMMIT}," >>/tmp/log; git commit-tree "$@" | tee -a /tmp/log' your-branch-here
[...]
$ cat /tmp/log
70d609ba7bc58bb196a2351ba26afc5db0964ca6,d9071b49743701c7be971f76ddc84e76554516c7
0d1146dcabc00c45fb9be7fe923c955f7b6deb50,cb6813f9aca5e5f26fcc85007c5bb71552b91017
[...]

(That file, of course, has the format <original commit hash>,<new commit hash> .) (当然,该文件的格式为<original commit hash>,<new commit hash> 。)

I'm kind of curious what your intentions are with using this though. 我有点好奇你使用它的意图是什么。 It doesn't seem like information you'd need to typically know if you're using filter-branch the "right" way (ie, not manipulating existing published history). 如果您以“正确”的方式使用过滤器分支(即,不操纵现有的已发布历史记录),您通常不需要知道的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 过滤分支后相同提交的不同 SHA,当我合并到 dev 或 master 时,它不会失败吗? 我怎样才能防止这种情况? - Different SHAs for same commit after filter-branch, when I merge to dev or master wouldn't it fail? How can I prevent this? 如何在root提交上运行git filter-branch? - How can I run git filter-branch on the root commit? GIT-在筛选器分支之前删除旧的提交历史记录 - GIT - Remove old commit history before filter-branch 使用git filter-branch编辑旧的提交消息 - Edit an old commit message with git filter-branch 列出来自特定分支的 Git 提交 SHA,而不克隆存储库 - List Git commit SHAs from a specific branch without cloning the repository 使用git filter-branch --subdirectory-filter后,如何仍使用旧的repo并回收git空间? - After using git filter-branch --subdirectory-filter how do I still use old repo and reclaim git space? Git 过滤器分支到过滤器回购:标签未重写 - Git filter-branch to filter-repo : tags not rewritten 如何在运行git filter-branch后删除旧的历史记录? - How to delete the old history after running git filter-branch? 如何使用git filter-branch将文件添加到特定提交? - How to add a file to a specific commit with git filter-branch? git filter-branch导致了一个断开连接的历史记录:如何摆脱旧的提交? - git filter-branch led to a disconnected history: how to get rid of the old commits?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM