git git合并后丢失文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21263211/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 09:37:06  来源:igfitidea点击:

missing files after git merge

gitgit-merge

提问by Martin H.

Some weeks ago I create a feature branch, I'm developing in. There are severals commits and some new files as well. I can change from master branch to my development branch and versa vice and everything is fine.

几周前,我创建了一个功能分支,我正在开发。有几个提交和一些新文件。我可以从主分支更改为我的开发分支,反之亦然,一切都很好。

Today I tried to merge my branch back to the master branch. Therefore I changed to master and called

今天我试图将我的分支合并回主分支。因此我改为主人并打电话

git merge mydevbranch

which resulted in several merge conflicts. i resolved these conflicts with

这导致了几次合并冲突。我解决了这些冲突

git mergetool

But now, I realized, there are some files missing within the result I have to commit. So there are two questions: Shouldn't be there all merged items on my hard disk after merging? How can I proceed to get the real merge result (master + my feature branch).

但是现在,我意识到,我必须提交的结果中缺少一些文件。所以有两个问题:合并后我的硬盘上不应该有所有合并的项目吗?我如何才能获得真正的合并结果(主 + 我的功能分支)。

采纳答案by Dong

For your first question: Shouldn't be there all merged items on my hard disk after merging?

对于你的第一个问题:合并后我的硬盘上不应该有所有合并的项目吗?

I do a experiment on my own environment. It has the same effect as you has. So my conclusion is that, the file deleted in your master branch will not come back in your master branch if you merge the develop branch which has that same file.

我在自己的环境中做了一个实验。它和你有同样的效果。所以我的结论是,如果您合并具有相同文件的开发分支,则在您的主分支中删除的文件将不会返回到您的主分支中。

I think this makes sense. Let's assume that you had deleted lots of unwanted files in the master branch and commit those removals. Then you merge the develop branch who has all those unwanted files. If all those unwanted files are 'added' into the master branch again, you may be upset to see that happen because you have to take time to delete them again.

我认为这是有道理的。假设您在 master 分支中删除了大量不需要的文件并提交了这些删除。然后合并拥有所有这些不需要的文件的开发分支。如果所有这些不需要的文件再次“添加”到 master 分支,您可能会因为看到这种情况而感到不安,因为您必须花时间再次删除它们。

回答by Martin H.

After some investigation I found the following. The file was added by me on master before creating the branch (that's why it was in my dev-branch). But now the crazy thing: The file was deleted in master afterwards by a colleague, but without any status information. Status log only shows the creation of the file. So the merge was correct, but due to the missing status information it was not comprehensible to me.

经过一番调查,我发现了以下内容。该文件是我在创建分支之前在 master 上添加的(这就是它在我的 dev-branch 中的原因)。但现在疯狂的事情是:该文件后来被同事在 master 中删除,但没有任何状态信息。状态日志仅显示文件的创建。所以合并是正确的,但由于缺少状态信息,我无法理解。

回答by Marcin Barylski

Check if there is nothing in stash

检查 stash 中是否没有任何东西

git stash pop

For new files, please make sure you add them first (git status should list them)

对于新文件,请确保先添加它们(git status 应该列出它们)

git add

The best docs about Git at all, including branches: http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging

关于 Git 的最佳文档,包括分支:http: //git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging

回答by Asenar

It's not possible to lose files that way.

不可能以这种方式丢失文件。

You may try this alternative:

你可以试试这个替代方案:

git checkout mydevbranch
# following command to find the previous state easier if you are not familiar with reflog
git branch tmp-checkpoint 
git rebase master

Then solve conflicts. If the files are still missing, you can use git bisect (see man page) to find the point where they disappear

然后解决冲突。如果文件仍然丢失,您可以使用 git bisect(参见手册页)找到它们消失的点