简体   繁体   English

如何git rebase仅更改的文件

[英]How to git rebase only changed files

I'd like to do a git rebase of a repo of HTML files. 我想做一个HTML文件库的git rebase。 I have a repo that looks like: 我有一个类似的仓库:

-- A -- B 
   \
    \-- C -- D -- E -- F

I'd like to rebase F onto B, but I have the problem that I don't want C. C introduced a change that reflowed the text in ALL of the HTML files. 我想将F重新设置为B,但是我有一个问题,就是我不希望C。C引入了一项更改,该更改将所有 HTML文件中的文本重新排列。 I only want the changes from D, E, and F for the files that changed in those commits. 我只希望这些提交中更改的文件来自D,E和F的更改。

So, in other words, I'd like: 因此,换句话说,我想要:

-- A -- B -- D' -- E' -- F'

EXCEPT: I want the last commit to include the files from F that are returned from git diff --name-only C..F , and the rest of the files from B. 例外:我希望最后一次提交包含git diff --name-only C..F返回的F的文件,以及B的其余文件。

The thing that doesn't work for me is: 对我不起作用的是:

git rebase --onto B D F

Because I have to do a messy merge, and manually pick which files I want. 因为我必须进行混乱的合并,并手动选择所需的文件。 I could add -X theirs but I get the files from C that I don't want. 我可以添加-X theirs但是我从C中得到了我不想要的文件。

So, my crappy not git way of doing it is to just create one new custom commit on top of B, where I copy in the files from F that are in git diff --name-only C..F . 因此,我最糟糕的做法不是在B上创建一个新的自定义提交,然后在其中复制git diff --name-only C..F来自F的文件。

Is there a better git way to do this? 有更好的git方法吗?

(For reference, here's how I do it without fully using git): (仅供参考,这是我不完全使用git的方法):

git diff --name-only C..F | xargs -I{} -n1 sh -c "git show F:{} > {}"

First, git cherry-pick -n C . 首先, git cherry-pick -n C The -n means it will do the cherry pick but not commit it. -n表示将执行樱桃选择,但不提交。 Then make whatever modifications you like and commit. 然后进行所需的任何修改并提交。 Let's call this new commit C1 . 我们将此新提交称为C1

Then git rebase --onto C1 CF . 然后git rebase --onto C1 CF Note that the range is exclusive . 请注意,范围是排他的 It will rebase from, but not including, C. The result is D to F. This makes more sense when you're working with branches like git rebase --onto master this that . 它将基于C,但不包括C。结果是D到F。这在使用git rebase --onto master this that分支时更有意义- git rebase --onto master this that

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM