Reputation: 26745
I have some changes in my current branch from a particular path in another branch. (There was a dependency that needed bringing across.)
I initially brought these changes across using the following commands:
git checkout master
git checkout -b new_branch
git checkout other_feature path/to/dependency
Now I need to unpick this dependency, or at least aspects of it (a subpath within path/to/dependency
).
I have run git diff --name-status master..new_branch path/to/dependency
and it displays the differences as expected.
However, git checkout master path/to/dependency
does not successfully revert this directory's contents to that of master. Why is this the case?
Upvotes: 1
Views: 136
Reputation: 1323145
Just in case, try:
git checkout --force master path/to/dependency/subpath/to/revert
# or:
git checkout --ours master path/to/dependency/subpath/to/revert
from git checkout
man page:
-f
--force
When switching branches, proceed even if the index or the working tree differs from HEAD. This is used to throw away local changes.
When checking out paths from the index, do not fail upon unmerged entries; instead, unmerged entries are ignored.
That first option '--force' should be what you are looking for, but in case merges are involved, then the second option (--ours
, not compatible with --force
) can help too.
--ours
--theirs
When checking out paths from the index, check out stage
#2
(ours
) or#3
(theirs
) for unmerged paths.
Upvotes: 1