1

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the answer. However, I get the following error message when attempting the force ours checkout: fatal: git checkout: --ours/--theirs, --force and --merge are incompatible when checking out of the index.
@bcmcfc what is the result of a git status, then? And a git branch?
On branch new_branch nothing to commit (working directory clean) and the full local branch list with the active branch (new_branch) starred.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.