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!
The only way I can fathom this possible situation is if you created two different files, each with the same filename, in independent branches.
i.e. let's say that the master
and dev
branches already exist.
file.txt
to master
dev
, then again create and commit file.txt
to dev
. Now because you have created two distinct files, git views them as two separate entities despite the same filename, defeating the whole purpose of version control.file.txt
from dev
dev
into master
, and low and behold file.txt
still exists in master
, and this makes sense because like I said, git views the two files as completely independent.notice if you had not deleted file.txt
from dev
and attempted a merge, then you would have gotten a merge conflict because git wouldn't know how to handle two different entities with the same path/filename.
If this is your scenario, then I'm going to risk arrogance and say you're doing it wrong ;)
The point of a version control system is to let the tool manage your differences between a file at different stages in time as well as the relationship of those changes to other files in the repository.
My suggestion to improve the workflow in this situation would be to checkout the specific file from the other branch:
file.txt
to master
checkout dev
, then just grab the particular file from the other branch
git checkout master -- file.txt
In this situation, you will still be on the dev
branch, but have now added file.txt
from the master
branch.
now git recognizes that these are the same entity. so you can delete the file and commit the removal in dev
dev
into master
will now delete file.txt
from master
I had the same problem. In my case I think the problem was that, when I did the merge, my copy of the merged-from branch was outdated compared to the remote. (a colleague had done the deletion, not me)
In any case, what fixed it was deleting the whole working copy and cloning it anew.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With