Need git rebase -Xignore-all-space to preserve my space

前端 未结 2 1693
北恋
北恋 2021-01-05 01:00

I am doing a rebase of a big change, with a lot of whitespace changes. In order for the merge to work at all, I need -Xignore-all-space.

According to git --help reba

相关标签:
2条回答
  • 2021-01-05 01:45

    I guess your only option is to use a git merge instead, this way it doesn't swap theirs and ours.

    0 讨论(0)
  • 2021-01-05 01:47

    There's a way, but it's ugly. You're much better off keeping whitespace and "real" changes separate, and upstreaming the former first before doing the latter. But if you find yourself in this situation...

    For the sake of simplicity, I am assuming that everything is in a single commit in the current branch. This should work in a multi-commit situation, it just (again) will be more ugly. I'm also assuming the branch to rebase onto is master, and your working branch forked from it somewhere down the line.

    1. git merge master -Xignore-all-space --no-commit. Resolve the merge to your satisfaction.
    2. rm .git/MERGE_*. We're going to convince git that this is a regular commit, not a merge.
    3. git commit -a -m "Pseudo-merge from master"
    4. git rebase -i HEAD^^ and "fixup" the last change into your original one. We could have combined this with the previous step, but actually committing the pseudo-merge gives us a commit to reset to in case something goes wrong later. If this is a multiple-commit change you're working with, you may want/need to move the psuedo-merge change to a different point in the history before you squash it, to properly simulate the rebase.
    5. git rebase HEAD^ --onto master -Xtheirs The "-Xtheirs" says to always prefer their changes, but "ours" and "theirs" are flipped in a rebase, so that means to always prefer ours. This is safe, since we manually resolved the rebase (via merge) already.
    0 讨论(0)
提交回复
热议问题