git checkout –merge <tree-ish> — <paths> not working as expected

When I try to merge my working tree changes to a file with the ones at tree-ish by checking its path out the former changes are overwritten with the latter changes.

I did not expect this behavior. Instead I would expect Git to replace the file content with conflict markers displayed in the default, merge or diff3 style depending on whether the --merge, --conflict=merge or --conflict=diff3 option was given to git checkout.

Given the following use case:

git init
echo foo > foobar
git add foobar
git commit --message=blabla foobar
echo bar > foobar
git checkout --conflict=diff3 HEAD -- foobar

I lose the local changes made with echo bar > foobar.

Also why does the manual page git-checkout(1) mention the -m and --conflict=<style> options in the synopsis git checkout [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] [--] <paths>…? What is the purpose of these two options?

I use git version 1.9.4.msysgit.2 on Microsoft Windows 7.

  • Merge conflict error, when there was no change in mentioned file
  • Git octopus merge with unrelated repositoies
  • How to fix a pull request branch that suffered a bad merge?
  • Git merge only the final result of a development branch
  • How to rebase after a merge?
  • Removing branch merged in history?
  • Does Git have trouble merging compiled files?
  • How do I merge with --no-ff in SmartGit/hg?
  • One Solution collect form web for “git checkout –merge <tree-ish> — <paths> not working as expected”

    I see why you expected that behavior — the doc says “when checking out paths from the index” when describing the behavior you’re getting, and this looks like a doc bug to me. Notice that when describing the behavior you want, it says “when switching branches”. I’d [mis]read that pair exactly as you did, and get surprised exactly the same way.

    I think that, to describe what it’s doing now accurately, the doc should just say “when checking out paths” and lose the “from the index” part, but I’d also argue for what you want, that “when checking out from a commit or tree [whether or not paths are specified]” for the merge behavior would be a better choice, and also that it should be changed to work that way — a course that’s made easier to justify since atm the doc doesn’t actually say what it’s going to do here

    Git Baby is a git and github fan, let's start git clone.