Git本地缺少文件的difftool

huangapple go评论101阅读模式
英文:

Git difftool with missing file locally

问题

I am using BeyondCompare来进行合并,但我遇到了一个关于本地文件不存在的问题。

在分支dev上,我有文件src/foo.hpp,但在master上我没有这个文件。

当我执行:

git checkout master
git difftool dev

我无法保存我的文件,因为它指向/dev/null

这是我的.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

如果我执行:

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

我发现Git不允许在本地创建文件。

除此之外,是否有其他解决方法?:

touch src/foo.hpp
git add src/foo.hpp
git commit -m "Add missing file"
英文:

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"

答案1

得分: 2

其中的一种解决方法,

git checkout master

# 从分支“dev”引入文件
git checkout dev src/foo.hpp

git status
git commit

更一般地,只要文件存在于该修订中,您可以从任何修订中检出任何文件,

git checkout $revision $path

如果要复制修订的文件到新路径而不检出它,

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

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

# 例如
git show dev:src/foo.hpp > src/bar.hpp
英文:

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

huangapple
  • 本文由 发表于 2023年5月15日 15:04:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76251604.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定