简体   繁体   English

当解决方案是删除冲突的文件时,有没有办法使git rerere工作?

[英]Is there a way to make git rerere work when the resolution is to delete the conflicted file?

Here's the deal. 这是交易。 master has a file, file1. 母版有一个文件file1。 I branch, and delete that file in the branch. 我分支,然后在分支中删除该文件。 Meanwhile, I modify file1 on master. 同时,我在master上修改file1。 Boom, conflict. 繁荣,冲突。

When I merge my branch into master, the resolution is to delete the file. 当我将分支合并到master时,解决方案是删除文件。 I'm trying to use git rerere to be able to do the same resolution multiple times, but as you can see below it doesn't record the resolution in the case when you're deleting the file. 我正在尝试使用git rerere来多次执行相同的解析,但是正如您在下面看到的那样,当您删除文件时,它没有记录解析度。

I can't find any docs on this specifically, is this just a limitation of rerere ? 我找不到关于此的任何文档,这仅仅是rerere的限制吗?

 |system| brad-macbook-air in ~/tmp
± bb+ih |master ✓| → touch file1.txt

 |system| brad-macbook-air in ~/tmp
± bb+ih |master ✗| → git add . && git commit -m 'File1'
[master (root-commit) 95a807e] File1
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 file1.txt

 |system| brad-macbook-air in ~/tmp
± bb+ih |master ✓| → git checkout -b delete_file_1
Switched to a new branch 'delete_file_1'

 |system| brad-macbook-air in ~/tmp
± bb+ih |delete_file_1 ✓| → git rm file1.txt
rm 'file1.txt'

 |system| brad-macbook-air in ~/tmp
± bb+ih |delete_file_1 ✗| → git commit -m 'rm file1'
[delete_file_1 83d1a57] rm file1
 1 file changed, 0 insertions(+), 0 deletions(-)
 delete mode 100644 file1.txt

 |system| brad-macbook-air in ~/tmp
± bb+ih |delete_file_1 ✓| → git checkout master
Switched to branch 'master'

 |system| brad-macbook-air in ~/tmp
± bb+ih |master ✓| → echo 'hello' > file1.txt

 |system| brad-macbook-air in ~/tmp
± bb+ih |master ✗| → git commit -am 'update file1'
[master 16f6541] update file1
 1 file changed, 1 insertion(+)

 |system| brad-macbook-air in ~/tmp
± bb+ih |master ✓| → git merge delete_file_1 
CONFLICT (modify/delete): file1.txt deleted in delete_file_1 and modified in HEAD. Version HEAD of file1.txt left in tree.
Automatic merge failed; fix conflicts and then commit the result.

 |system| brad-macbook-air in ~/tmp
± bb+ih |master ✗| → git rm file1.txt
file1.txt: needs merge
rm 'file1.txt'

 |system| brad-macbook-air in ~/tmp
± bb+ih |master ✗| → git commit --no-edit
[master 4791204] Merge branch 'delete_file_1'

Here we should see something like "recorded resolution for file1.txt", but we don't. 在这里,我们应该看到类似“ file1.txt的已记录分辨率”的信息,但事实并非如此。 Just to be sure it's not recording our resolution, we keep going and do the exact same merge again: 为了确保它没有记录我们的分辨率,我们继续进行并再次进行完全相同的合并:

 |system| brad-macbook-air in ~/tmp
± bb+ih |master ✓| → git reset head^
Unstaged changes after reset:
D   file1.txt

 |system| brad-macbook-air in ~/tmp
± bb+ih |master ✗| → git co .

 |system| brad-macbook-air in ~/tmp
± bb+ih |master ✓| → git merge delete_file_1 
CONFLICT (modify/delete): file1.txt deleted in delete_file_1 and modified in HEAD. Version HEAD of file1.txt left in tree.
Automatic merge failed; fix conflicts and then commit the result.

And here you can see that git rerere doesn't remember the conflict resolution (and in fact incorrectly leaves the file in the tree). 在这里您可以看到git rerere不记得解决冲突的方法(实际上是错误地将文件留在树中)。

As the way it stands right now, No. rerere tries to record previous resolutions based on hunks in each conflicted file. 按照目前的状态,re.rerere尝试根据每个冲突文件中的块记录以前的分辨率。 In case of delete, rerere sees it only as no hunks to resolve. 在删除的情况下,rerere仅将其视为无法解决的难题。

I had problems too when the feature branch includes a new file that doesn't exist in the main branch , but in order to get the feature branch merged into the master and have it work correctly, it requires a small modification to this new file. 当功能分支包含主分支中不存在的新文件时,我也遇到了问题,但是为了使功能分支合并到母版中并使其正常工作,需要对该新文件进行一些小的修改。 The git rerere doesn't realize that this is part of the entire merge process and hence never records the changes required. git rerere没有意识到这是整个合并过程的一部分,因此从不记录所需的更改。

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

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