我想指定我正在使用的自定义合并驱动程序位于我的存储库的根目录中,名为 mergebans.py。我已经尝试过以下路径......
$ git merge master
../mergebans.py .merge_file_h3Bq8r .merge_file_2sLmCK .merge_file_H38i62 7: 1: ../mergebans.py .merge_file_h3Bq8r .merge_file_2sLmCK .merge_file_H38i62 7: ../mergebans.py: not found
../mergebans.py .merge_file_knuMAl .merge_file_Pg9f5D .merge_file_Gb0JzW 7: 1: ../mergebans.py .merge_file_knuMAl .merge_file_Pg9f5D .merge_file_Gb0JzW 7: ../mergebans.py: not found
$ git merge master
../mergebans.py .merge_file_TBZ2ia .merge_file_dHaTFA .merge_file_7wEJ20 7: 1: ../mergebans.py .merge_file_TBZ2ia .merge_file_dHaTFA .merge_file_7wEJ20 7: ../mergebans.py: not found
../mergebans.py .merge_file_pzgQqr .merge_file_rvHXOR .merge_file_TYk5ci 7: 1: ../mergebans.py .merge_file_pzgQqr .merge_file_rvHXOR .merge_file_TYk5ci 7: ../mergebans.py: not found
$ git merge master
/home/steam/.config/SCP Secret Laboratory/mergebans .merge_file_sDGMpM .merge_file_GiChes .merge_file_2JJM27 7: 1: /home/steam/.config/SCP Secret Laboratory/mergebans .merge_file_sDGMpM .merge_file_GiChes .merge_file_2JJM27 7: /home/steam/.config/SCP: not found
/home/steam/.config/SCP Secret Laboratory/mergebans .merge_file_OacBRN .merge_file_4qUpGt .merge_file_ElPev9 7: 1: /home/steam/.config/SCP Secret Laboratory/mergebans .merge_file_OacBRN .merge_file_4qUpGt .merge_file_ElPev9 7: /home/steam/.config/SCP: not found
$ git merge master
fatal: bad config line 21 in file .git/config
Run Code Online (Sandbox Code Playgroud)
如何修复.git/config才能正确找到该mergebans.py文件?
您在 \xe2\x80\x94 行上定义的字符串,无论driver其文本是什么,\xe2\x80\x94 都会传递到您的 shell,无论它是什么(如果是 Unix-ish 系统,可能是 sh 或 bash),并且由您的 shell 决定处理字符串。所以第一个技巧是设置字符串本身。
在这里,只需输入空格就可以了:
\n\n[merge "netbeans"]\n driver = this has spaces\nRun Code Online (Sandbox Code Playgroud)\n\n我们可以用以下方法测试git config --get:
$ git config --get merge.netbeans.driver\nthis has spaces\n$ git config --get merge.netbeans.driver | hexdump -C\n00000000 74 68 69 73 20 68 61 73 20 73 70 61 63 65 73 0a |this has spaces.|\n00000010\nRun Code Online (Sandbox Code Playgroud)\n\n然而,shell 会将其视为三个“单词”;我们希望这三个单词成为 shell 术语中的单个单词。这里反斜杠可以工作,但是git config解析会消耗一层反斜杠,所以我们需要将反斜杠加倍:
[merge "netbeans"]\n driver = this\\\\ has\\\\ spaces\nRun Code Online (Sandbox Code Playgroud)\n\n这使:
\n\n$ git config --get merge.netbeans.driver\nthis\\ has\\ spaces\nRun Code Online (Sandbox Code Playgroud)\n\n(这次我将把十六进制转储或其他字符查看留给读者)。
\n\n或者,我们可以将整个字符串放在双引号或单引号中。实验表明git config --get它git config本身不吃单引号:
[merge "netbeans"]\n driver = \'this has spaces\'\n\n$ git config --get merge.netbeans.driver\n\'this has spaces\'\nRun Code Online (Sandbox Code Playgroud)\n\n但它确实吃双引号:
\n\n[merge "netbeans"]\n driver = "this has spaces"\n$ git config --get merge.netbeans.driver\nthis has spaces\nRun Code Online (Sandbox Code Playgroud)\n\n后者的解决方案是引用双引号,例如使用反斜杠:
\n\n[merge "netbeans"]\n driver = \\"this has spaces\\"\n$ git config --get merge.netbeans.driver\n"this has spaces"\nRun Code Online (Sandbox Code Playgroud)\n\n(这说明了为什么我们之前必须将反斜杠加倍)。
\n\n其中哪一个(如果有)适合您的shell取决于您的 shell。在大多数情况下,我倾向于使用双引号,但这里单引号最容易编写,并且适用于我的shell,所以我会使用:
\n\n driver = \'/home/steam/...\'\nRun Code Online (Sandbox Code Playgroud)\n\n(除了我首先会避免在路径名中添加空格,这样就不必执行任何操作...)。
\n\n最后,尽管您可能确实想$PATH针对这种特殊情况执行此操作,但当 shell 搜索您时,像这样硬编码完整路径名很少会很好。如果存在其他程序P和Q应该访问的程序X ,则当P和Q运行时X应该打开。例如,Git 自己的内部管道程序位于,因此当您运行 时,前端会在 的前面插入自己的路径,然后只运行它找到名为 的第一个可执行文件。这意味着您可以编写自己的 Git 程序\xe2\x80\x94,包括合并策略或合并驱动程序\xe2\x80\x94 之类的管道程序,然后 Git 加上 shell 可以为您找到它们。例如,如果您编写一个命令,将其放在 中的某个位置,然后运行,您会发现 Git 运行您自己的命令(增强后指向 git-core 代码,以便可以获取$PATHgit --exec-pathgit commandgit--exec-path$PATHgit-commandgit-command$PATHgit-frob$PATHgit frobgit-frob$PATHgit-frobgit-sh-setup轻松获取源代码)。