git 在 Gitlab 上,如何比较两个不同提交的文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50069291/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 13:06:36  来源:igfitidea点击:

On Gitlab, how to compare a file of two different commits

gitgitlab

提问by yigal

On Gitlab, how to compare a file of two different commits? I know that that on command line git, the command is:

在 Gitlab 上,如何比较两个不同提交的文件?我知道在命令行 git 上,命令是:

git diff commit1 commit12 -- file_name

What is the link format to do this on gitlab?

在 gitlab 上执行此操作的链接格式是什么?

See my related question

看我的相关问题

回答by robertbeb

It will compare commits, you will be able to find file in list.

它将比较提交,您将能够在列表中找到文件。

  1. go to Repository > Compare
  2. paste this url: https://gitlab.com/$USER/$REPO/compare?from=$SHA1&to=$SHA2
  3. hit enter (notice: gitlab will set 'Source' and 'Target' properly)
  4. click button 'compare'
  1. 转到存储库 > 比较
  2. 粘贴这个网址:https: //gitlab.com/$USER/$REPO/compare?from=$SHA1&to=$SHA2
  3. 点击回车(注意:gitlab 将正确设置“源”和“目标”)
  4. 单击“比较”按钮

回答by anapsix

It appears the direct URL for compare is as follows

看起来比较的直接网址如下

# 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

To compare a single file across two commits, one needs to get a blob id of the file first, and append it to the compare url following a octothorp (#); gotta find a way to get that id though

要在两次提交中比较单个文件,首先需要获取文件的 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}

回答by singuliere

You first need to get the sha1digest of the file path you are interested in (for instance with the sha1sumcommand). You can then build the URL to display the diff between two git ref(i.e. branch names or commit hash or tags) as follows:

您首先需要获取您感兴趣的文件路径的sha1摘要(例如使用sha1sum命令)。然后,您可以构建 URL 以显示两个git ref(即分支名称或提交哈希或标签)之间的差异,如下所示:

https://gitlab.com/<project>/-/compare/<ref1>...<ref2>#<sha1>

Here is an example with the AN/R5/L15/S2018/IDS/000/020/RUANR5L15S2018IDS20864.jsonfilename. Its sha1 is f88a5e03ecc7854e8955927af33f2ea9d090ddaf:

这是一个带有AN/R5/L15/S2018/IDS/000/020/RUANR5L15S2018IDS20864.json文件名的示例。它的 sha1 是f88a5e03ecc7854e8955927af33f2ea9d090ddaf

$ echo -n AN/R5/L15/S2018/IDS/000/020/RUANR5L15S2018IDS20864.json | sha1sum
f88a5e03ecc7854e8955927af33f2ea9d090ddaf

Comparing it between the 878bd4f4f7edbabad3c691a7df3e317348d4ca77and 59e63f529a7fe5f28131dec36f253dca46b8ba9ccommits is done with the URL: https://git.en-root.org/tricoteuses/data.tricoteuses.fr/Agenda_XV/-/compare/59e63f529a7fe5f28131dec36f253dca46b8ba9c...878bd4f4f7edbabad3c691a7df3e317348d4ca77#f88a5e03ecc7854e8955927af33f2ea9d090ddaf

它比较之间878bd4f4f7edbabad3c691a7df3e317348d4ca7759e63f529a7fe5f28131dec36f253dca46b8ba9c提交与URL完成:https://git.en-root.org/tricoteuses/data.tricoteuses.fr/Agenda_XV/-/compare/59e63f529a7fe5f28131dec36f253dca46b8ba9c...878bd4f4f7edbabad3c691a7df3e317348d4ca77#f88a5e03ecc7854e8955927af33f2ea9d090ddaf

The page will also display other diffs, not just the one you are interested in. But it will move you right where the diff of the file starts and you can ignore the rest.

该页面还将显示其他差异,而不仅仅是您感兴趣的差异。但它会将您移到文件差异开始的位置,您可以忽略其余的差异。

There are a few GitLab feature requeststo make it easier for the user to discover this in the future.

一些 GitLab 功能请求可以让用户在未来更容易发现这一点。

回答by david zhang

if you want to compare one file different version

如果你想比较一个文件的不同版本

1.Repositoy->Commits->select file->click Side-by-side

1.Repositoy->Commits->选择文件->点击Side-by-side

2.you will see two windows,left is old version and right is new version.

2.你会看到两个窗口,左边是旧版本,右边是新版本。