问题描述
我有一个主人和一个开发分支。我在两者中都进行了提交。
我也删除了dev中的一些文件。
我在master中进行了其他提交,所以这个master分支是最近的。
我的问题是将dev合并到master中不会删除文件。
Git认为这些文件存在于master中,因此在合并期间保留这些文件。
如何合并这两个分支并强制Git应用在dev中进行的所有提交?包括已删除的文件。
请您帮忙!
为了证明这一点,我必须尝试重现您的场景。希望你能看到你在做什么不同。
创建一个新的存储库
mkdir test
cd test
git init
创建并添加一些文件到master branch
echo one> 1.txt
echo two> 2.txt
git add。
git commit -minit repo
创建新分支并添加/删除某些文件
git checkout -b新
git checkout -b新
echo three> 3.txt
rm 2.txt
git add。
git status
git commit -m
在master中提交更多更改
git checkout master
tree
验证文件在新的中仍然被删除 h1>
git checkout新
git checkout新
树
合并到master中
git checkout master
git checkout master
git merge new master
树
您可以看到,在 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.
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
create and add some files to master branch
echo one > 1.txt
echo two > 2.txt
git add .
git commit -m "init repo"
create new branch and add/delete some files
git checkout -b new
echo three > 3.txt
rm 2.txt
git add .
git status
git commit -m "changes in new"
commit some more changes in master
git checkout master
echo update >> 1.txt
git commit -am "update master"
tree
verify files still deleted in new
git checkout new
tree
merge new into master
git checkout master
git merge new master
tree
as you can see, the file 2.txt
deleted in the new
branch is now definitely deleted in master
following the merge.
这篇关于将旧分支合并到主服务器时,Git不会应用已删除的文件。我如何告诉Git应用已删除的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!