Git合并 - 不完整,缺少文件和文件夹 [英] Git Merge - Incomplete, Missing files and Folders

查看:963
本文介绍了Git合并 - 不完整,缺少文件和文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  git checkout master 
git pull。

我试图将开发分支合并到master中。开发

一切似乎都顺利,虽然我解决了这些问题并提交了冲突。但是,当我检查这个新合并的工作树是从开发中丢失了很多文件夹和文件。

  git status //显示冲突&安培;不会列出一些文件/文件夹。 
git commit -a

创建提交55ffdd1:将分支'dev'合并到master

git diff dev --name-status

产生:

  D文件夹/lm.gif 
D folders / lmh.gif
...

所以没有显示'git status'的文件/文件夹。它也没有出现在最后,当我修复合并冲突。



另外,当我尝试再次合并它说:

  git merge dev 
已经是最新的。

然而,master分支显然缺少dev分支中的文件/文件夹。这是为什么?不应该添加该文件夹及其所有内容吗? '文件夹'正在开发分支上进行跟踪,所以当我进行合并时它不应该被拉下来?



当早先出现合并冲突时,git停止合并过程,并跳过一堆文件/文件夹?



开发分支有很多变化,过去我可以用git搞砸了吗?现在某些文件/文件夹不会合并?



(当我第一次创建开发分支时,我不知道自己在做什么,并且执行了像重置,还原等疯狂的事情。)



希望你们中的一位git guru在堆栈溢出时知道答案。 :)



感谢,
Quang






回答



感谢Walter,是的,发生了什么事。



经过一番调查后,我发现它是一个发生了什么并不复杂。事实证明,


  1. dev从主站分支,它拥有所有文件。

  2. A第三个分支,让我们称之为清理,从开发分支。

  3. 清理分支删除所有文件。

  4. 清理分支合并?)与主人。在这一点上,这些文件被删除了。 '已清理'的分支消失了。

  5. 在dev上,这些文件仍然存在,我继续添加到这个分支,编辑文件很久。

  6. dev与master合并,以前被清理过的所有文件都没有了。

希望这有助于除我之外的其他人学习了很多关于如何使用git log,git show,git reflog试图调试发生的事情。



谢谢!



如何解决



所以我这样做就是将dev中所有以前删除的内容合并到master中。


  1. 获取所有已删除的文件/文件夹(在开发中但不在新合并的主文件中) git diff dev --name-status | grep D> deleted_files

  2. 所有文件和文件夹的输出列表 git log --name-status> file_history 将使用它来确定已删除文件的最新更新版本。

  3. 逐个浏览deleted_files列表,找到最新的版本在file_history并恢复它。例如: git checkout 25b8a44 view.php 25b8a44 ...是view.php的最新更新版本的提交。我尝试了> cherry-pick ,只是一个简单的 git checkout dev view.php 但我明确使用commit id,它融合了更多的历史。 (包括导致文件首先被删除的提交。)

  4. 一旦所有被删除的文件都返回一个快速检查 git diff dev --name -status | grep D 显示所有文件都被复制过。然后就像Walter说的那样:


>解决方案

听起来好像git认为,在dev和预合并头之间的某个点上,缺少的文件被删除了。这是我能想到为什么git会在合并期间默默地放置跟踪文件的唯一原因。



不幸的是,我不知道解决这个问题的好方法。我可能只是手动重新添加从dev分支中删除的所有文件(或者使用一点bash脚本),然后添加到 git commit --amend 修改合并提交以包含它们。


I was trying to merge a dev branch into master.

git checkout master    
git pull . dev

Everything seemed to go well, although there were conflicts I fixed these and commited. But when I checked this newly merged working tree is missing a lot of folders and files from dev.

git status  // Shows conflicts & doesn't list some files/folders.    
git commit -a 

Created commit 55ffdd1: Merge branch 'dev' into master  

git diff dev --name-status

Produces:

D       folders/lm.gif
D       folders/lmh.gif
...

So the files/folders that didn't show up on 'git status'. It also didn't show up at the end when I fixed the merged conflicts.

Also when I try to merge again it says:

git merge dev    
Already up-to-date.

Yet the master branch clearly is missing files/folders from the dev branch. Why is that? Shouldn't that folder and all it's contents be added? 'folders' is being tracked on the dev branch, so shouldn't it have gotten pulled over when I did the merge?

When there was a merge conflict earlier did git stop the merge process and skipped a bunch of files/folders?

The dev branch had quite a lot of changes, could I have messed something up with git in the past that now certain files/folders wouldn't have merged?

(When I first created the dev branch I didn't know what I was doing and did crazy things like reset, reverts etc.)

Hoping one of you git guru's here on stack overflow knows the answer. :)

Thanks, Quang


Answer

Thanks Walter, Yes this is what happened.

After doing some investigating I found out it was a little complicated what happened. It turned out that.

  1. dev branched from master, it had all the files.
  2. A third branch, lets call it "cleaned", branched off of dev.
  3. cleaned branch deleted all the files.
  4. cleaned branch merged (or something?) with master. At this point the files were deleted off of master. And the 'cleaned' branch disappeared.
  5. on dev, the files are still there and I continued adding to this branch, editing files for quite some time.
  6. dev merged with master and all the files that was deleted previously by cleaned were gone.

Hope this helped someone besides me who learned quite a lot about how to use git log, git show, git reflog trying to debug what happened.

Thanks!

How to Fix

So this is what I did to merge all of the contents in dev that was previously deleted back onto master.

  1. Got all the files/folders that was deleted (on dev but not on the newly merged master) git diff dev --name-status | grep D > deleted_files
  2. Output list of all files and folders git log --name-status > file_history Gonna be using this to figure out the last updated version of the deleted file.
  3. Go through the list of deleted_files one by one, find the the most updated version in file_history and restore it. Example: git checkout 25b8a44 view.php 25b8a44... was the commit with the last updated version of view.php. I tried cherry-pick and just a straight git checkout dev view.php but i found explicitly using the commit id, it merge more of it's history. (Including the commit that cause the file to be deleted in the first place.)
  4. Once all the deleted files are back a quick check git diff dev --name-status | grep D shows that all files are copied over. Then like Walter said an ammend commit git commit --amend :)

解决方案

It sounds like git thinks that the missing files were deleted on the master at some point between where it branches from dev and the pre-merge head. That's the only reason I can think of for why git would silently drop tracked files during a merge.

Unfortunately, I don't know a good way to fix that. I'd probably just re-add all the deleted files from the dev branch manually (or with a little bit of bash scripting), and then to a git commit --amend to revise the merge commit to include them.

这篇关于Git合并 - 不完整,缺少文件和文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆