跳到正文
DEV Community· Specita·· 1 小時前AI 評分47

GitHub 如何比較兩個標籤,查看版本之間的變更

GitHub compare two tags: see what changed between releases

AI 導讀

GitHub 的標籤比較功能可顯示兩個版本之間的提交、檔案變更及貢獻者。比較時,兩點和三點的差異在於比較方式,標籤位於不同分支時結果可能不同;同一比較亦可透過 gh CLI 和 REST API 執行。

正文

To compare two tags on GitHub, open https://github.com/OWNER/REPO/compare/v1.2.0...v1.3.0. The first tag is the base, and the second is what you're comparing it to. GitHub shows the commits, the changed files, and the contributors between them. It's the quickest way to answer "what went into this release?", and the same comparison works from the gh CLI and the REST API.

How to compare two tags in the browser

You have two routes. GitHub's docs describe appending /compare to your repository's path.

  1. Open https://github.com/OWNER/REPO/compare.
  2. In the base dropdown, pick the older tag. You can type a tag name there, even though it's labeled as a branch.
  3. In the compare dropdown, pick the newer tag.

Or just edit the URL directly:

https://github.com/acme/app/compare/v1.2.0...v1.3.0

Put the older tag first. If you reverse them, GitHub often shows "There isn't anything to compare", or the differences in the wrong direction.

The page has three useful parts: the commit list, the pull requests behind those commits if you follow them, and the file diff. For a large release, start with the commit list and only open the diff for the risky parts.

Two dots and three dots

This trips up nearly everyone at some point. Your URL can use either.

Syntax What it shows Use it when
v1.2.0...v1.3.0 (three dots) Changes on v1.3.0 since the point where the two lines diverged You want to see what the newer tag added. The default
v1.2.0..v1.3.0 (two dots) The direct difference between the two tags You want the exact difference between the two

For two tags on a straight line of history, the two forms give the same result. They differ when your tags sit on different branches. A hypothetical example: a hotfix tag v1.2.1 on a release branch, compared to v1.3.0 on main. Three dots shows what main has that the common ancestor doesn't, leaving out the hotfix's own changes. Two dots shows the difference between the code in each tag, including what the hotfix has that v1.3.0 lacks. If you're asking "did the hotfix make it into 1.3.0?", two dots gives you a clearer answer.

How to compare from the command line

With plain Git, make sure that your tags are fetched first:

git fetch --tags

git log --oneline v1.2.0..v1.3.0   # commits in v1.3.0 and not in v1.2.0
git diff --stat v1.2.0 v1.3.0      # files changed, with counts
git diff v1.2.0 v1.3.0 -- src/     # the diff, limited to a folder

Note how the dots mean something different here. In git log, two dots means commits reachable from the second and not the first, which is usually what you want for release notes. In git diff, two dots and a space do the same thing. This mismatch between log and diff is a long-standing Git quirk.

To list the pull requests in a range, the commit subjects usually include their numbers when you squash-merge. To open the comparison from your terminal:

gh browse --no-browser   # prints the repository URL
gh api repos/acme/app/compare/v1.2.0...v1.3.0 --jq '.total_commits, .files[].filename'

How to compare with the API

GitHub's REST API has a compare endpoint that returns the same data as JSON:

curl -H "Authorization: Bearer $GITHUB_TOKEN" \
  https://api.github.com/repos/acme/app/compare/v1.2.0...v1.3.0

The response includes total_commits, commits, and files. Results are paged, and a very large comparison won't return every file, so check the docs if your releases are big. Use a read-only token, and keep it out of your scripts.

Why a comparison can look wrong

If the page says there's nothing to compare, check the order of the tags, then whether both tags exist on GitHub. A tag you created locally doesn't appear until you push it with git push origin v1.3.0.

If the commit count is huge, check the tag you think of as the base. If you tagged on a branch that was later rebased, or moved a tag, the shared history may be less than you'd expect. Don't move release tags. Create a new one, so that a tag means the same thing forever.

If the changes don't match what's in production, the tag may not be what you shipped. Compare the commit SHA your deployment reports with the commit the tag points at. A build from an untagged commit is a common cause.

Using a comparison for a release review

A comparison is useful for more than curiosity. Before a release, read it with these questions:

  • Which changes touch payment, auth, or data migrations?
  • Did anything merge after QA signed off?
  • Are there dependency or lockfile changes you didn't expect?
  • Who should check the riskiest change?

After an incident, the same page narrows the search. If a crash started with v1.3.0, this comparison is your list of suspects. It's also how you plan an iOS app rollback or a hotfix, since it shows what you'd be taking out. To turn the list into something readable, use a release notes template.

Tags for mobile releases

Tag every build you might ship, including the build number. For example, ios/2.4.0+317 and android/2.4.0+318. Now every App Store or Google Play version maps to a commit, and you can compare the two on the same day that a client asks what changed.

GitHub guidance checked on November 4, 2026.

This article was created with the help of AI and checked against GitHub's documentation. It first appeared on the Specita blog.

來源:DEV Community · dev.to