Issue
I am trying to replace a directory as it exists in current branch with a directory from another branch. Eclipse fails to delte files that where then in the original branch but not in the other branch.
Example:
Current branch: A
Directory: src
In this branch src has a file called NoLongerRequired.java
Another branch B
Directory: src
In this branch src
does NOT have a file called NoLongerRequired.java
I am on branch A
and want to remove A's src
directory and replace it with B's src
directory
So I select src
directory and go to Replace with Branch Tag or Commit
option in Eclipse and choose branch B
.
However, I still see NoLongerRequired.java
in the src
directory.
Solution
It looks like the implemented action is similar to git checkout B -- src/
: the files listed in B
are checked out, but the files tracked in A
and not in B
are left untouched.
If you have git installed on your machine, with version 2.25 or higher, you can do it from the command line using 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
does the deletion for you.
Answered By - LeGEC