0

I am using BeyondCompare to do merge, but I have an issue with not existing files locally.

On branch dev I have the file src/foo.hpp, but on master I don't have this file.

When I do :

git checkout master
git difftool dev 

I cannot save my file, because it pointing to /dev/null.

Here my .gitconfig:

[difftool "bc4"]
    cmd = "\"/mnt/c/Program Files/Beyond Compare 4/BComp.exe\" \"$(wslpath -aw \"$LOCAL\")\" \"$(wslpath -aw \"$REMOTE\")\" /lefttitle=\"$(wslpath -aw \"$LOCAL\")\" /righttitle=\"$(wslpath -aw \"$REMOTE\")\""

[difftool "echo"]
    cmd = "echo" $LOCAL $REMOTE

If I do:

git difftool -techo dev 
/tmp/hxqHC9_foo.hpp /dev/null

I see that Git does not allow for creating file locally.

Is there a workaround other than this?:

touch src/foo.hpp
git add src/foo.hpp
git commit -m "Add missing file"
LeGEC
  • 46,477
  • 5
  • 57
  • 104
nowox
  • 25,978
  • 39
  • 143
  • 293

1 Answers1

2

One of the workarounds,

git checkout master

# Introduce the file from the branch "dev"
git checkout dev src/foo.hpp

git status
git commit

More generally, you can check out any file from any revision as long as the file exists in that revision,

git checkout $revision $path

If you want to copy a file of a revision to a new path without checking it out,

git show ${revision}:${path} > ${newpath}

# Or
git cat-file -p ${revision}:${path} > ${newpath}

# For example
git show dev:src/foo.hpp > src/bar.hpp
ElpieKay
  • 27,194
  • 6
  • 32
  • 53