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

后端 未结 7 796
面向向阳花
面向向阳花 2021-02-05 02:38

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

git diff commit1 commit12 -- file_name
         


        
7条回答
  •  别那么骄傲
    2021-02-05 03:04

    You first need to get the sha1 digest of the file path you are interested in (for instance with the sha1sum command). 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:

    https://gitlab.com//-/compare/...#
    

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

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

    Comparing it between the 878bd4f4f7edbabad3c691a7df3e317348d4ca77 and 59e63f529a7fe5f28131dec36f253dca46b8ba9c commits is done with the 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 requests to make it easier for the user to discover this in the future.

提交回复
热议问题