簡體   English   中英

比較GIT的2個不同分支上的2個文件

[英]Compare 2 files on 2 different branches on GIT

我必須比較GIT的2個不同分支上的2個文件。之后,我需要將其合並到master。

我看見了這個 :

git diff branch1:full/path/to/foo.txt branch2:full/path/to/foo-another.txt

您能告訴我如何填充完整路徑以及branch1和branch2嗎?

更新:我曾這樣嘗試過,但是沒用。你能告訴我為什么嗎?

git diff 
master:https://github.com/MyGit/blob/master/My.Web/App/tenant/views/propertymana
gement/index.less access-ui:https://github.com/MyGit/blob/access-
ui/My.Web/App/tenant/views/propertymanagement/index.less

上面的命令給出了這個錯誤

fatal: Path 'https://github.com/MyGit/blob/master/My.Web/App/t
enant/views/propertymanagement/index.less' does not exist in 'master'

您能告訴我如何填充完整路徑以及branch1和branch2嗎?

它是工作樹中當前路徑的相對路徑,而不是文件的URI。

對於具有兩個文件夾dir1和dir2的本地工作樹,您現在位於dir1中,並且想要比較dir1中的文件,請使用以下命令:

git diff branch1:file1.c branch2:file1

要比較dir2中的文件,請使用以下命令。

git diff branch1:../dir2/file2.c branch2:../dir2/file2.c

您也可以比較不同文件夾中具有不同文件名的文件,即,以下命令可以。

git diff branch1:file1.c branch2:../dir2/file2.c

git diff yourbranch1 yourbranch2 -- yourfile.txt

或使用Meld或任何git diff工具。

您不需要完整路徑,但是需要相對於相關樹的路徑。

git-diff文檔中:

 git diff [--options] <commit> <commit> [--] [<path>…​]

   This is to view the changes between two arbitrary <commit>.

采用:

git diff master access-ui My.Web/App/tenant/views/propertymanagement/index.less

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM