简体   繁体   English

Git:当工作分支中删除了文件时,如何让* git rebase upstream / master *解决?

[英]Git: How to make *git rebase upstream/master* work around when there is removed files in the working branch?

I am new to GIT and have a question that may be stupid but from so far I searched there is no post mentioning this. 我是GIT的新手并且有一个可能是愚蠢的问题但是到目前为止我搜索过没有帖子提到这个。 Here is the situation: 情况如下:

                A                A'
upstream/master-+---+----+----+-----+
                    |
myworkingbranch     +---+---+---
                    A   B   C 

I fork a repo at point A, then make my own commit B, C,... at the same time, the original repo makes its commit A'. 我在A点分叉回购,然后自己提交B,C,......同时,原始仓库使其提交A'。 Generally, by applying git rebase, I can make B, C, ... based on A' instead on A. However, In commit B, I have some files deleted, which remain in A'. 通常,通过应用git rebase,我可以基于A'而不是A来制作B,C,......但是,在提交B中,我删除了一些文件,它们保留在A'中。 Then, every time I excute git rebase, it complains the conflicts on deleted/removed files, which means I need to solve the conflict manually by mergetool or sth else. 然后,每次我执行git rebase时,都会抱怨已删除/删除文件的冲突,这意味着我需要通过mergetool或者其他方式手动解决冲突。

I get from the github's help page that it seems the question is divided to two parts: 我从github的帮助页面得知,问题似乎分为两部分:

  1. by git rebase, commits B,C would be canceled and myworkingbranch would go back to A in the cache. 通过git rebase,提交B,C将被取消,myworkingbranch将返回缓存中的A. During this, how about the files that deleted in B? 在此期间,B中删除的文件怎么样? Will they be restored? 他们会被恢复吗? I think not because if it will then there would be no problem. 我想不是因为如果它会那么没有问题。

  2. if the deleted files is not restored, when I apply commit A' from upstream/master, which contains changing to the deleted files, there are conflicts. 如果删除的文件没有恢复,当我从上游/主机应用提交A'时,包含更改为已删除的文件,则存在冲突。 And every time rebasing, the conflicts need to be solved manually. 每次重新定位时,都需要手动解决冲突。 Since there could be hundreds of such files, it is awful. 由于可能有数百个此类文件,因此非常糟糕。

Qestion: While an upstream/master's commit that contains changing to the files which is deleted in myworking branchis is applied, is there an elegant way of git rebase, that can Automatically omit the changes refering to those deleted files? 问题:虽然应用了包含更改为myworking branchis中删除的文件的上游/主控提交,但是有一种优雅的git rebase方法,可以自动省略引用那些已删除文件的更改吗? in both the two parts of the problem I mentioned above? 在我上面提到的问题的两个部分?

I did find that for git merge, I can use .gitattribute file to omit certain files in the upstream branch. 我确实发现,对于git merge,我可以使用.gitattribute文件来省略上游分支中的某些文件。 Will it work for git rebase? 它适用于git rebase吗? I guess it would not because, if I add those .gitattribute files via a commit, say, D in myworkingbranch, then when git rebase, status A would be in cache, not D, which again contains no .gitattribute files and conflict would occur during patching on A' 我想它不会因为,如果我通过提交添加那些.gitattribute文件,比如说,在myworkingbranch中的D,那么当git rebase时,状态A将在缓存中,而不是D,它再次不包含.gitattribute文件并且会发生冲突修补A'期间

Thanks in advance for the help. 先谢谢您的帮助。

You could activate git rerere , and memorize the conflict resolution once . 你可以激活git rerere ,并记住一次冲突解决方案。

The subsequent rebase wouldn't be stopped by the same conflicts. 后续的rebase不会被相同的冲突所阻止。


During this, how about the files that deleted in B ? 在此期间, B中删除的文件怎么样? Will they be restored? 他们会被恢复吗? I think not because if it will then there would be no problem. 我想不是因为如果它会那么没有问题。

Yes, a rebase starts by a checkout of the new base ( A' ): the files are restored in the index. 是的,一个rebase开始于检查新基数( A' ):文件在索引中恢复。
And then it applies B and C . 然后它适用于BC

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

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