Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
This question accurately resembles this question:
Git merge doesn't merge a file the second time
I will just copy and paste the original question since it describes the background of my question:
I have a master branch with some stuff, let's say file README. I also have a dev branch, child of master, with some additional files, let's say file README2. I do the following:
git merge dev
from master and get the file README2 merged into master. Now I remove it:
git rm README2
Now when I merged dev again, I expected that I will get README2 file merged into master, because it's not in the master anymore. But Git reports there are no changes and nothing to merge. This actually suits me, but I don't understand how is this so, since branch dev at this point clearly has README2 file, while master doesn't.
However, I'm not asking why it happens, I understand that git rebase/merge works at the level of the commit tree, not of individual files, but I would like to ask - in this instance, how would you get back the README2 file from branch
dev
? Or in other words, is there a simple way to re-apply the merge as if it happens the first time, without having to delete commits?
EDIT: to put it another way, is there a way to overwrite the files with the files in the other branch, while being asked to solve conflicts? (the exact functionality of using merge)
–
–
how would you get back the
README2
file from branch
dev
You could use the new
git restore
command (
Git 2.23, Q3 2019
), and restore the missing file after your merge:
git switch main
git restore -s dev -- ./README2
# add and commit
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.