将旧分支合并到主服务器时,Git不会应用已删除的文件。我如何告诉Git应用已删除的文件? [英] Git does not apply deleted files when merging an old branch into the master. How can I tell Git to apply deleted files?

查看:363
本文介绍了将旧分支合并到主服务器时,Git不会应用已删除的文件。我如何告诉Git应用已删除的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主人和一个开发分支。
我在两者中都进行了提交。
我也删除了dev中的一些文件。
我在master中进行了其他提交,所以这个master分支是最近的。



我的问题是将dev合并到master中不会删除文件。



Git认为这些文件存在于master中,因此在合并期间保留这些文件。



如何合并这两个分支并强制Git应用在dev中进行的所有提交?包括已删除的文件。



请您帮忙!

解决方案




如果git在合并分支中被删除,git在合并期间不保留文件。 - Nils_M


为了证明这一点,我必须尝试重现您的场景。希望你能看到你在做什么不同。



创建一个新的存储库



  mkdir test 
cd test
git init




在/test/.git /

中初始化空的Git存储库



创建并添加一些文件到master branch



  echo one> 1.txt 
echo two> 2.txt
git add。
git commit -minit repo




(root-commit)feaa910]初始化回购

2个文件已更改,2个插入(+)

创建模式100644 1.txt

创建模式100644 2。 txt




创建新分支并添加/删除某些文件

  git checkout -b新




切换到一个新分支'new'




  echo three> 3.txt 
rm 2.txt
git add。
git status




在分支新增功能

要提交的更改:

(使用git reset HEAD ...停用)

已删除:2.txt

新文件:3.txt



  git commit -m 




[new db6b1a0] new new
2个文件已更改,1个插入(+),1个删除( - )

删除模式100644 2.txt

创建模式100644 3.txt




在master中提交更多更改



  git checkout master 




切换到分支'master'


blockquote>

  echo update>> 1.txt 
git commit -amupdate master




[master 912a520] update master

1个文件已更改,1个插入(+)




  tree 






├──1.txt

└──2.txt



验证文件在新的中仍然被删除 h1>

  git checkout新




切换到分支'new'




 






├──1.txt

└──3.txt



合并到master中

  git checkout master 




切换到分支'master'



  git merge new master 




移除2.txt

由'递归'策略合并。

2.txt | 1 -

3.txt | 1 +

2个文件已更改,1个插入(+),1个删除( - )

删除模式100644 2.txt

创建模式100644 3.txt




 






├──1.txt

└──3.txt


您可以看到,在 2.txt 文件>新的分支现在在合并后的 master 中肯定被删除。


I have a master and a dev branch. I made commits in both. I also deleted some files in dev. I made other commit in master, so this master branch is more recent.

My issue is that merging dev into master dont delete files.

Git consider that these files exists in master and consequently, keep them during the merge.

How can I merge these two branches and force Git to apply all and every commits made in dev ? including deleted files.

Thks for your help!

解决方案

Merges definitely delete files when there's not a conflict with changes in branches.

git does not preserve files during merging if they are deleted in the merging branch. - Nils_M

To prove it to myself, I had to try to reproduce your scenario. See this demonstration in hopes that you can see what it is you are doing differently.

create a new repository

mkdir test
cd test
git init

Initialized empty Git repository in /test/.git/

create and add some files to master branch

echo one > 1.txt
echo two > 2.txt
git add .
git commit -m "init repo"

[master (root-commit) feaa910] init repo
2 files changed, 2 insertions(+)
create mode 100644 1.txt
create mode 100644 2.txt

create new branch and add/delete some files

git checkout -b new

Switched to a new branch 'new'

echo three > 3.txt
rm 2.txt 
git add .
git status

On branch new
Changes to be committed:
(use "git reset HEAD ..." to unstage)

deleted: 2.txt
new file: 3.txt

git commit -m "changes in new"

[new db6b1a0] changes in new
2 files changed, 1 insertion(+), 1 deletion(-)
delete mode 100644 2.txt
create mode 100644 3.txt

commit some more changes in master

git checkout master

Switched to branch 'master'

echo update >> 1.txt 
git commit -am "update master"

[master 912a520] update master
1 file changed, 1 insertion(+)

tree

.
├── 1.txt
└── 2.txt

verify files still deleted in new

git checkout new

Switched to branch 'new'

tree

.
├── 1.txt
└── 3.txt

merge new into master

git checkout master

Switched to branch 'master'

git merge new master

Removing 2.txt
Merge made by the 'recursive' strategy.
2.txt | 1 -
3.txt | 1 +
2 files changed, 1 insertion(+), 1 deletion(-)
delete mode 100644 2.txt
create mode 100644 3.txt

tree

.
├── 1.txt
└── 3.txt

as you can see, the file 2.txt deleted in the new branch is now definitely deleted in master following the merge.

这篇关于将旧分支合并到主服务器时,Git不会应用已删除的文件。我如何告诉Git应用已删除的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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