我正在尝试用另一个分支的目录替换当前分支中存在的目录。Eclipse无法对原始分支中的文件进行delte,但不能对其他分支中的位置进行delte。
示例:
Current branch: A
Directory: src
在这个分支中,src有一个名为NoLongerRequired.java
的文件
Another branch B
Directory: src
在这个分支中,src
没有名为NoLongerRequired.java
的文件
我在分支A
上,希望删除A's src
目录并将其替换为B's src
目录因此,我选择src
目录并转到Eclipse中的Replace with Branch Tag or Commit
选项,然后选择分支B
。
但是,我仍然在src
目录中看到NoLongerRequired.java
。
看起来实现的操作类似于git checkout B -- src/
:在B
中列出的文件已检出,但在A
中跟踪的文件和在B
中未跟踪的文件保持不变。
如果您的机器上安装了版本为2.25或更高的git,您可以使用git restore
:从命令行执行此操作
# use --staged to set B's content in the staging area :
git restore --source B --staged -- src/
# --worktree to set the content on disk :
git restore --source B --worktree -- src/
# a word of warning : if you have uncommitted changes in src/, this may delete
# files which aren't committed in git yet.
# you can combine both options in one call :
git restore --source B --staged --worktree -- src/
git restore
为您删除。