[英]On GitLab, how to compare a file of two different commits
在 GitLab 上,如何比較兩個不同提交的文件? 我知道在命令行 git 上,命令是:
git diff commit1 commit12 -- file_name
在 GitLab 上執行此操作的鏈接格式是什么?
看我的相關問題
它將比較提交,您將能夠在列表中找到文件。
看起來比較的直接網址如下
# compare URL, where ref_source and ref_target can be commit SHA, tag, or branch
https://${gitlab_host}/${repo_path}/compare/${ref_target}...${ref_source}
# tag example 1, comparing tag v1.5.1 to master
https://${gitlab_host}/${repo_path}/compare/v1.5.1...master
# tag example 2, comparing tag v1.5.1 to tag v1.5.2
https://${gitlab_host}/${repo_path}/compare/v1.5.1...v1.5.2
# commit example 1, comparing commit SHA to master
https://${gitlab_host}/${repo_path}/compare/f6098082f...master
# commit example 2, comparing commit SHA to another commit SHA
https://${gitlab_host}/${repo_path}/compare/f6098082f...2b8daf28
要在兩次提交中比較單個文件,首先需要獲取文件的 blob id,並將其附加到比較 url 后跟一個 octothorp ( #
); 必須找到一種方法來獲得那個 id
# compare URL, where ref_source and ref_target can be commit SHA, tag, or branch, and file_blob
https://${gitlab_host}/${repo_path}/compare/${ref_target}...${ref_source}#${file_blob}
其他答案都沒有正確的步驟來通過當前版本的 Gitlab GUI 顯示兩個分支之間的差異。 這樣做:
master
(或任何您的默認分支調用)更改目標分支。您首先需要獲取您感興趣的文件路徑的sha1摘要(例如使用sha1sum命令)。 然后,您可以構建 URL 以顯示兩個git ref (即分支名稱或提交哈希或標簽)之間的差異,如下所示:
https://gitlab.com/<project>/-/compare/<ref1>...<ref2>#<sha1>
這是一個帶有AN/R5/L15/S2018/IDS/000/020/RUANR5L15S2018IDS20864.json文件名的示例。 它的 sha1 是f88a5e03ecc7854e8955927af33f2ea9d090ddaf :
$ echo -n AN/R5/L15/S2018/IDS/000/020/RUANR5L15S2018IDS20864.json | sha1sum
f88a5e03ecc7854e8955927af33f2ea9d090ddaf
它878bd4f4f7edbabad3c691a7df3e317348d4ca77和59e63f529a7fe5f28131dec36f253dca46b8ba9c提交之間的比較與URL完成: https://git.en-root.org/tricoteuses/data.tricoteuses.fr/Agenda_XV/-/compare/59e63f529a7fe5f28131dec36f253dca46b8ba9c...878bd4f4f7edbabad3c691a7df3e317348d4ca77#f88a5e03ecc7854e8955927af33f2ea9d090ddaf
該頁面還將顯示其他差異,而不僅僅是您感興趣的差異。但它會將您移到文件差異開始的位置,您可以忽略其余的差異。
有一些 GitLab 功能請求可以讓用戶在未來更容易發現這一點。
您可以打開兩個選項卡:
Repository -> Commits
),您可以從那里獲得任何給定提交的SHA
(右側有復制按鈕);Repository -> Compare
),在頂部,在source
和target
,通過要比較的兩個提交的SHA
字符串。如果你想比較一個文件的不同版本
1.Repositoy->Commits->選擇文件->點擊Side-by-side
2.你會看到兩個窗口,左邊是舊版本,右邊是新版本。
只要可以在屏幕上查看代碼,您就可以通過 GitLab 網絡界面通過簡單的點擊來完成此操作。
目前,它以以下方式對我有用:
導航到 Repository -> Commits -> a commit - Options -> Tag 為兩個提交添加標簽。
導航存儲庫 -> 比較 -> 在下拉列表中選擇標簽。
Source 值應該是最后一次提交的標簽,Target - 初始提交的標簽。
單擊比較。
除了使用此 url 來自 @anapsix 的答案之外:
https://${gitlab_host}/${repo_path}/-/compare/${ref_target}...${ref_source}
該解決方案仍然有效,但${ref_target}
和${ref_source}
不是提交 SHA 密鑰。 您將需要該密鑰的簡短版本:僅前 8 個字符。
我可以通過以下操作比較提交中的文件:
資料庫->提交
選擇所需的分支並提交
這樣就可以並行比較所有文件中的所有更改。 在該提交消息的正下方是此語句(顯然您會有所不同)
顯示18個更改的文件,具有209個添加項和68個刪除項
18 changed files
是一個下拉菜單,其中列出了所有更改的文件。 選擇您要比較的文件。 這會將列表縮小為僅感興趣的文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.