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
What is the link format to do this on GitLab?
See my related question
The git diff command is commonly used to get the unstaged changes between the index and working directory. It can be also used to show changes between two arbitrary commits. To view the changes between two commits, you can provide the commit hashes.
To see the changes between two commits, you can use git diff ID1.. ID2 , where ID1 and ID2 identify the two commits you're interested in, and the connector .. is a pair of dots. For example, git diff abc123.. def456 shows the differences between the commits abc123 and def456 , while git diff HEAD~1..
You can also compare two arbitrary commits in your repository or its forks on GitHub in a two-dot diff comparison. To quickly compare two commits or Git Object IDs (OIDs) directly with each other in a two-dot diff comparison on GitHub, edit the URL of your repository's "Comparing changes" page.
You can compare files between two Git commits by specifying the name of the ref that refers to the commits you want to compare. A ref may be a commit ID or HEAD, which refers to the current branch. Let's compare two commits in our Git repository.
It will compare commits, you will be able to find file in list.
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
# 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}
And the compare UI can be reached at https://${gitlab_host}/${repo_path}/-/compare
, where you can select source and target refs via drop-down.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With