如何对单个文件进行rebase以便对其进行所有更改?我无法找出git rebase
可以执行此任务的任何选项。
答案 0 :(得分:3)
如果我理解你想要什么,你想要从repo历史中的一系列提交中删除对指定文件的所有更改(提交可能还包括对其他文件的更改)(a),然后重新将更改添加到该指定文件作为历史记录(b)之上的一个提交。
Git确实可以在整个存储库的基础上工作,而不是基于每个文件,所以你在git中找不到简单的方法来做到这一点。
我认为您需要git diff <begin> <end> -- <file>
的组合来为(b)创建补丁,然后git filter-branch
或bfg repo cleaner
来删除对相关文件的任何更改(a)的提交范围。
答案 1 :(得分:0)
为便于说明,假设您要重新配置的文件为target.c
。进一步假设还有其他文件(bar.c和foo.c)也同时更改。
最后,假设您的git历史记录与此类似(最近的记录排在最前)。
* END - desired state of target.c
...
* c2 - more changes to bar.c, foo.c, target.c
* c1 - some changes to bar.c, foo.c, target.c
* START - the commit you want to start your changes from
您可以像这样隔离对target.c
的更改:
git checkout END
git reset --soft START
git add target.c
git commit -m "just changes to target.c"
这时,您只需从START提交一次提交,只需更改target.c:
* new - just changes to target.c
* START - the commit you want to start your changes from
原始提交(c1,c2,...结束)仍然存在,您可以将其他文件提取到其他提交中,等等。