Git Merge - 不完整、丢失的文件和文件夹 [英] Git Merge - Incomplete, Missing files and Folders

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

问题描述

我试图将一个 dev 分支合并到 master 中.

I was trying to merge a dev branch into master.

git checkout master    
git pull . dev

一切似乎都很顺利,尽管我解决了这些冲突并提交了冲突.但是当我检查这个新合并的工作树时,它缺少来自 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

产生:

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

所以没有出现在git status"上的文件/文件夹.当我修复合并的冲突时,它也没有出现在最后.

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?

之前发生合并冲突时,git 是否会停止合并过程并跳过一堆文件/文件夹?

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

dev 分支有很多变化,我是否可以在过去用 git 搞砸一些现在某些文件/文件夹不会合并的东西?

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?

(当我第一次创建 dev 分支时,我不知道自己在做什么,做了一些疯狂的事情,比如重置、恢复等)

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

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

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

谢谢,广

谢谢 Walter,是的,这就是发生的事情.

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 从 master 分支出来,它拥有所有文件.
  2. 第三个分支,我们称之为cleaned",从 dev 分支出来.
  3. cleaned 分支删除了所有文件.
  4. 已清理分支与 master 合并(或其他什么?).此时,文件已从 master 中删除.清理过的"分支消失了.
  5. 在 dev 上,文件仍然存在,我继续添加到这个分支,编辑文件很长一段时间.
  6. dev 与 master 合并,之前被cleaned 删除的所有文件都没有了.

希望这能帮助除我之外的其他人,他们学到了很多关于如何使用 git log、git show、git reflog 试图调试发生的事情.

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.

谢谢!

所以这就是我将 dev 中先前删除的所有内容合并回 master 的方法.

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

  1. 得到了所有被删除的文件/文件夹(在 dev 上而不是在新合并的 master 上)git diff dev --name-status |grep D >删除的文件
  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 但我发现明确使用提交 ID,它合并了更多的历史.(包括首先导致文件被删除的提交.)
  4. 一旦所有删除的文件都恢复了快速检查 git diff dev --name-status |grep D 显示所有文件都被复制过来.然后就像沃尔特说的修改提交 git commit --amend :)
  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 :)

推荐答案

听起来 git 认为丢失的文件在 master 上从 dev 分支到预合并头之间的某个点被删除了.这是我能想到的为什么 git 会在合并期间默默删除跟踪文件的唯一原因.

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.

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

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 Merge - 不完整、丢失的文件和文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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