添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
愉快的钥匙扣  ·  用extern出现undefined ...·  1 年前    · 
低调的菠菜  ·  curl ...·  2 年前    · 
开心的棒棒糖  ·  element ui Error in ...·  2 年前    · 
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)

Thanks that makes sense, but in case I don't remember what I changed, there's no way to somehow overwrite my files with the other branch files while asking to solve conflicts (exactly like with merge) ? – sir-haver Aug 28, 2022 at 20:51 Fwiw the format of this question is quite poor. it would benefit from the edit being reworded as the title and showing, not describing, the situation. It’s an odd/confusing choice to quote a different question. – AD7six Aug 28, 2022 at 21:22

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.