Eclipse:"替换为分支、标签或版本"无法按预期工作



我正在尝试用另一个分支的目录替换当前分支中存在的目录。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为您删除。

最新更新