.gitconfig를 사용하여 diff 도구 구성
.gitconfig 파일과의 차이점을 위해 다른 도구를 사용하도록 Git을 어떻게 구성합니까?
내 .gitconfig에 있습니다.
[diff]
tool = git-chdiff #also tried /bin/git-chdiff
작동하지 않습니다; 그냥 일반 명령 행 diff를 엽니 다. 내가 할 때
export GIT_EXTERNAL_DIFF=git-chdiff
그런 다음 git diff
외부 diffing 도구를 엽니 다 (따라서 외부 diff 도구 스크립트가 올바르게 작동한다는 것을 알고 있습니다). diff 도구의 .gitconfig 구성에 문제가 있습니까?
Git은 미리 정의 된 다양한 "디폴트"(kdiff3, kompare, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, spread, opendiff, p4merge 및 araxis)를 제공하며, 자신을 지정합니다. 사전 구성된 difftools 중 하나 (예 : "vimdiff")를 사용하려면 다음 행을 추가하십시오 ~/.gitconfig
.
[diff]
tool = vimdiff
이제 "git difftool"을 실행하고 원하는 도구를 사용할 수 있습니다.
반면에 자신의 difftool을 지정하면 조금 더 많은 작업이 필요합니다. 선호하는 diff 도구 / 뷰어로 'git diff'출력을 보려면 어떻게합니까?를 참조하십시오 .
이를 수행하는 추가 방법 (명령 행에서) :
git config --global diff.tool tkdiff
git config --global merge.tool tkdiff
git config --global --add difftool.prompt false
처음 두 줄은 difftool과 mergetool을 설정합니다 tkdiff
-선호 사항에 따라 변경하십시오. 세 번째 줄은 성가신 프롬프트를 비활성화하므로 때릴 때마다 git difftool
difftool이 자동으로 시작됩니다.
다른 사람들은 이것에 대해 99 %의 대답을했지만 한 단계는 빠졌습니다. (제 답변은 OS X에서 나올 것이므로 파일 경로를 적절히 변경해야합니다.)
다음과 같이 변경하십시오 ~/.gitconfig
.
[diff]
tool = diffmerge
[difftool "diffmerge"]
cmd = /Applications/Diffmerge.app/Contents/MacOS/diffmerge $LOCAL $REMOTE
이것은 diff 도구를 수정합니다. ~/.gitconfig
터미널에서 다음 명령을 입력 하여 직접 편집하지 않고이 문제를 해결할 수도 있습니다 .
git config --global diff.tool diffmerge
git config --global difftool.diffmerge.cmd "/Applications/DiffMerge.appContents/MacOS/diffmerge \$LOCAL \$REMOTE"
다른 사람들이 언급하지 않은 1 %는 이것을 사용할 때 실행할 수 없습니다 git diff myfile.txt
. 당신은 실행해야합니다 git difftool myfile.txt
.
다음은 diff 및 병합 도구를 구성하는 ~ / .gitconfig 부분입니다. 나는 SourceGear의 diffmerge를 좋아합니다. (사실상 매우 마음에 듭니다).
[merge]
tool = diffmerge
[mergetool "diffmerge"]
cmd = "diffmerge --merge --result=\"$MERGED\" \"$LOCAL\" \"$(if test -f \"$BASE\"; then echo \"$BASE\"; else echo \"$LOCAL\"; fi)\" \"$REMOTE\""
trustExitCode = false
[diff]
tool = diffmerge
[difftool "diffmerge"]
cmd = diffmerge \"$LOCAL\" \"$REMOTE\"
따라서, "diffmerge"라는 도구를 정의하고 [difftool "diffmerge"]
있습니다. 그런 다음 [diff] tool =
섹션 에서 "diffmerge"도구를 기본값으로 설정합니다 .
분명히 내 경로에 "diffmerge"명령이 있습니다. 그렇지 않으면 실행 파일의 전체 경로를 제공해야합니다.
이 스레드 에서 내 대답을 재현 하여 Git의 diff 도구로 비교할 수없는 설정에 더 구체적이었습니다. 내가 공유 한 모든 세부 사항은 일반적으로 모든 diff 도구에 똑같이 유용하므로 여기에서 공유하십시오.
우리가 실행하는 첫 번째 명령은 다음과 같습니다.
git config --global diff.tool bc3
위의 명령에서 항목 아래에 생성 .gitconfig
에서 발견 된 %userprofile%
디렉토리
[diff]
tool = bc3
그런 다음 아래 명령을 실행하십시오 ( 이 특별한 경우에는이 명령을 실행하는 것이 불필요하며 일부 특수한 경우에만 필요합니다. 잠시 후에 알게 될 것입니다 ).
git config --global difftool.bc3.path "c:/program files/beyond compare 3/bcomp.exe"
위의 명령은 .gitconfig
파일 에서 아래 항목을 만듭니다 .
[difftool "bc3"]
path = c:/program files/Beyond Compare 3/bcomp.exe
여기서 알아야 할 것은 열쇠 bc3
입니다. 이것은 시중에서 구할 수있는 특정 버전의 잘 알려진 비교 도구에 해당하는 잘 알려진 git 키 bc3
입니다 (Beyond Compare 도구의 세 번째 버전에 해당). 미리 정의 된 모든 키를 보려면 git difftool --tool-help
git bash 에서 명령을 실행하십시오 . 아래 목록을 반환합니다.
vimdiff
vimdiff2
vimdiff3
araxis
bc
bc3
codecompare
deltawalker
diffmerge
diffuse
ecmerge
emerge
examdiff
gvimdiff
gvimdiff2
gvimdiff3
kdiff3
kompare
meld
opendiff
p4merge
tkdiff
winmerge
xxdiff
위의 키를 사용하거나 사용자 정의 키를 정의 할 수 있습니다. 위에 나열된 키로 매핑되지 않는 새 도구 (또는 새로 출시 된 잘 알려진 도구 버전)를 설정하려는 경우 위에 나열된 키 또는 새 키로 자유롭게 매핑 할 수 있습니다. 자신 만의 맞춤 키.
비교 도구를 설정해야하는 경우
- 시장에서 완전히 새로운
또는
- A new version of an existing well known tool has got released which is not mapped to any pre-defined keys in git?
Like in my case, I had installed beyond compare 4. beyond compare is a well-known tool to git but its version 4 release is not mapped to any of the existing keys by default. So you can follow any of the below approaches:
I can map beyond compare 4 tool to already existing key
bc3
which corresponds to beyond compare 3 version. I didn't have beyond compare version 3 on my computer so I didn't care. If I wanted I could have mapped it to any of the pre-defined keys in the above list also e.g.examdiff
.If you map well known version of tools to appropriate already existing/well- known key then you would not need to run the second command as their install path is already known to git.
For e.g. if I had installed beyond compare version 3 on my box then having below configuration in my
.gitconfig
file would have been sufficient to get going:[diff] tool = bc3
But if you want to change the default associated tool then you end up mentioning the
path
attribute separately so that git gets to know the path from where you new tool's exe has to be launched. Here is the entry which foxes git to launch beyond compare 4 instead. Note the exe's path:[difftool "bc3"] path = c:/program files/Beyond Compare 4/bcomp.exe
Most cleanest approach is to define a new key altogether for the new comparison tool or a new version of an well known tool. Like in my case I defined a new key
bc4
so that it is easy to remember. In such a case you have to run two commands in all but your second command will not be setting path of your new tool's executable. Instead you have to setcmd
attribute for your new tool as shown below:git config --global diff.tool bc4 git config --global difftool.bc4.cmd "\"C:\\Program Files\\Beyond Compare 4\\bcomp.exe\" -s \"\$LOCAL\" -d \"\$REMOTE\""
Running above commands creates below entries in your
.gitconfig
file:[diff] tool = bc4 [difftool "bc4"] cmd = \"C:\\Program Files\\Beyond Compare 4\\bcomp.exe\" -s \"$LOCAL\" -d \"$REMOTE\"
I would strongly recommend you to follow approach # 2 to avoid any confusion for yourself in future.
Adding one of the blocks below works for me to use KDiff3 for my Windows and Linux development environments. It makes for a nice consistent cross-platform diff and merge tool.
Linux
[difftool "kdiff3"]
path = /usr/bin/kdiff3
trustExitCode = false
[difftool]
prompt = false
[diff]
tool = kdiff3
[mergetool "kdiff3"]
path = /usr/bin/kdiff3
trustExitCode = false
[mergetool]
keepBackup = false
[merge]
tool = kdiff3
Windows
[difftool "kdiff3"]
path = C:/Progra~1/KDiff3/kdiff3.exe
trustExitCode = false
[difftool]
prompt = false
[diff]
tool = kdiff3
[mergetool "kdiff3"]
path = C:/Progra~1/KDiff3/kdiff3.exe
trustExitCode = false
[mergetool]
keepBackup = false
[merge]
tool = kdiff3
If you want to have an option to use multiple diff tools add an alias to .gitconfig
[alias]
kdiff = difftool --tool kdiff3
Refer to Microsoft vscode-tips-and-tricks. Just run these commands in your terminal:
git config --global merge.tool code
But firstly you need add code
command to your PATH.
In Windows we need to run $git difftool --tool-help
command to see the various options like:
'git difftool --tool=<tool>' may be set to one of the following:
vimdiff
vimdiff2
vimdiff3
The following tools are valid, but not currently available:
araxis
bc
bc3
codecompare
deltawalker
diffmerge
diffuse
ecmerge
emerge
examdiff
gvimdiff
gvimdiff2
gvimdiff3
kdiff3
kompare
meld
opendiff
p4merge
tkdiff
winmerge
xxdiff
Some of the tools listed above only work in a windowed
environment. If run in a terminal-only session, they will fail.
and we can add any of them(for example winmerge) like
$ git difftool --tool=winmerge
For configuring notepad++ to see files before committing:
git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
and using $ git commit
will open the commit information in notepad++
참고URL : https://stackoverflow.com/questions/6412516/configuring-diff-tool-with-gitconfig
'IT story' 카테고리의 다른 글
HH : MM 시간 형식 일치를위한 정규식 (0) | 2020.06.19 |
---|---|
JavaScript에서 매개 변수없이 URL을 얻는 방법은 무엇입니까? (0) | 2020.06.19 |
AngularJS : 약속은 어디에 사용합니까? (0) | 2020.06.19 |
Xcode는 각 키 입력 후 스토리 보드를 계속 작성합니다. (0) | 2020.06.19 |
인스턴스의 클래스가 인터페이스를 구현하는지 확인하고 있습니까? (0) | 2020.06.19 |