使用重命名的文件对Git进行重新设置
我有一个重命名许多文件的分支,并且我试图将其重新建立到修改原始文件的master
上(最好不要将其分解为手动解决冲突的噩梦).
I've got a branch that renames many files, and I'm trying to rebase it onto master
where the original files have been modified (preferably without this devolving into a manual conflict-resolution nightmare).
-
我一直在本地
typescript
分支中将JavaScript项目移植到TypeScript.现在,所有.js
文件都已成为.ts
文件,并且某些语法已升级.
I've been porting a JavaScript project to TypeScript, in my local
typescript
branch. All of the.js
files have now become.ts
files, and some of the syntax has been upgraded.
与此同时,在master
分支上发生了对原始.js
文件的更改.
Meanwhile, changes to the original .js
files have happened on the master
branch.
我想将我的typescript
分支变基到master
上-但更改未正确合并,因为未检测到文件重命名-因此我们在git认为已删除的.js
文件进行更改的情况下再次发生冲突(但是实际上已将它们重命名为.ts
文件).
I want to rebase my typescript
branch onto master
-- but the changes are not merging correctly, as the file renames hadn't been detected -- so we're getting conflicts where changes are made to .js
files which git thinks had been deleted (however they have actually been renamed to the .ts
file).
我想我知道的东西
Git图形:
What I think I know
Git graph:
o-[typescript] .js files become .ts
|
| o-[master] changes to the .js files
| |
| o
|/
o-[root] common ancestor
所以,当站在root
分支中时:
So, while standing in the root
branch:
-
我可以运行以下命令来查看所有重命名:
git diff --name-status --find-renames=10% typescript
我了解 git merge 命令与--find-renames
功能,尽管我很难使它正常工作.
I understand that the git merge command has the same sort of --find-renames
functionality, though I'm having difficulty getting that to work.
- 更新:
git merge -X find-renames=10% mybranch
似乎是预期的语法.
-
Update:
git merge -X find-renames=10% mybranch
appears to be the expected syntax.
我了解 git rebase 可能支持find-renames
功能,尽管我仍不清楚如何使用.
I understand the git rebase might support find-renames
functionality, though I'm still not clear about how that might be used.
-
(否)也许从
root
起,我可以在检测到重命名的同时合并到typescript
中(例如:git merge -X find-renames=10% typescript
).然后,root就像typescript
一样,只是带有重命名(而不是大量删除/添加).
(Nope) Perhaps from
root
, I could merge intypescript
while detecting the renames (like this:git merge -X find-renames=10% typescript
). Then, root will be just liketypescript
, except with renames (rather than mass deletions/additions).
- 我希望从那里开始
git rebase master
,并且有了重命名后,操作将顺利进行并将编辑内容放入正确的文件中.- 更新:我尝试过此操作,但随后的重新部署并没有比以前做得更好.
- From there, I'm hoping I could just
git rebase master
, and with the renames having been in place, the operation will go smoothly and place the edits into the correct files.- Update: I tried this, but my subsequent rebase didn't go over any better than before.
(是)我认为也许需要使用
find-renames
选项执行重新设置本身.我正在对此进行调查...(Yep) I think perhaps the rebase itself needs to be performed with the
find-renames
option.. I'm investigating this...-
git rebase -X find-renames=10% master
-否 -
git rebase -X --find-renames=10% master
-不 -
git rebase --find-renames=10% master
-否 -
git rebase -X recursive --find-renames=10% master
-不 -
git rebase --merge -X find-renames=10% master
-不 -
git rebase --strategy-option="rename-threshold=10" master
-那就是票!可以!
-
git rebase -X find-renames=10% master
-- nope -
git rebase -X --find-renames=10% master
-- nope -
git rebase --find-renames=10% master
-- nope -
git rebase -X recursive --find-renames=10% master
-- nope -
git rebase --merge -X find-renames=10% master
-- nope git rebase --strategy-option="rename-threshold=10" master
-- that's the ticket! it works!
(不是)也许我需要以不同的方式看待这个问题?也许我应该从
master
开始,然后使用重命名检测对typescript
进行某种壁球合并(而不是进行任何类型的变基?)(Nope) Perhaps I need to look at the problem differently? Maybe I should start from
master
, and then do some kind of squash merge oftypescript
with the rename detection (rather than any kind of rebase?)- 我不需要
typescript
分支的历史记录,无论如何它都会被压缩成一个胖提交供审核.. - 更新::当我尝试此策略时,Git似乎停止工作.当我站在
root
分支时,我可以运行git merge -X find-renames=10 typescript
-它快进了到typescript
..(不是我希望的那样,我希望有一个具有重命名而不是添加/删除的新提交.)- 当我站在
master
分支中,并且运行 完全相同的命令 时,git告诉我:fatal: Unknown option for merge-recursive: -Xfind-renames=10
... - 现在,这困扰着我,因为我实际上没有输入它引用的内容(我确实包含了空格),而且对我来说唯一不同的是我当前所在的分支-如果可以的话是未知",那么为什么在其他分支中起作用?
- 无论如何,这令人毛骨悚然,而且似乎使这种方法无路可走.
- I don't need the
typescript
branch history, it will be squashed down to one fat commit for review anyways.. -
Update: It looks like Git stops working when I attempt this strategy.. When I'm standing in the
root
branch, I can rungit merge -X find-renames=10 typescript
-- and it fast-forwards totypescript
.. (not quite what I was hoping for, I was hoping for a new commit that had renames rather than additions/deletions..)- When I'm standing in the
master
branch, and I run the exact same command, git tells me this:fatal: Unknown option for merge-recursive: -Xfind-renames=10
... - Now, this bothers me, because I actually did not enter what it quoted (I did include the space), and the only thing that seems different to me, is which branch I'm currently standing in -- if the option is "Unknown", then why does it work when in a different branch?
- Anyways, so that's creepy, and seems to make this approach a dead-end.
- When I'm standing in the
- 当我站在
您可以在检测重命名时重新建立分支,例如:
git rebase --strategy-option="rename-threshold=10" master
自Git 2.8.0起,不赞成使用重命名阈值"一词,而使用查找重命名".
Since Git 2.8.0, the term 'rename-threshold' has been deprecated in favor of 'find-renames'.
目前,我正在使用Git 2.7.4,因此我只能实际验证以上命令是否适合我的情况-如果上述命令可能需要使用术语'find-renames'在您的情况下,在新版Git上不起作用...
在此示例中,
- 当前分支重新基于
master
- 指定了
10%
的重命名阈值 - 对
master
的原始文件更改将放置在新的(重命名的)文件中(与仅运行git rebase master
相对). - 请注意与
git diff
,git log
和git merge
命令中发现的类似重命名检测功能相比,语法有何不同
- the current branch is rebased onto
master
- the rename threshold of
10%
is specified - changes in
master
to the original files will be placed in the new (renamed) files (as opposed to running merelygit rebase master
). - note how the syntax is different compared to similar rename-detection functionality found in the
git diff
,git log
, andgit merge
commands
git rebase 文档对于在特别是..我以为我在某处的另一个命令中读到,"rename-threshold"一词已被弃用,尽管在这种情况下find-renames
似乎不能用作同义词-因此,如果有人知道更好的运行方式同样的命令,请提一下:)
The git rebase documentation isn't very clear about this rename-detection aspect in particular.. I thought I read in another command somewhere, that the term "rename-threshold" was deprecated, though in this context find-renames
did not seem to work as a synonym -- so if anybody knows about a better way to run this same command, please mention so :)