Skip to main content

Troubleshooting commits

Resolve common commit issues like incorrect user links, missing local commits, and push protection blocks.

Commits are linked to the wrong user

GitHub links a commit to a user by matching the email address in the commit header to an email address on a GitHub account. If your commits are linked to the wrong user or no user, update your Git email settings and add the email address to your account.

注意

If your commits are linked to another user, that does not give them access to your repository.

Commits are linked to another user

  1. Change the email address in your local Git configuration by following 设置提交电子邮件地址. If you work on multiple machines, change this setting on each one.
  2. Add the email address to your account by following 将电子邮件地址添加到GitHub帐户.

Future commits that use the email address will be linked to your account.

Commits are not linked to any user

To find out why a commit is not linked, inspect the commit on GitHub.

  1. 在 GitHub 上,导航到存储库的主页面。

  2. 在存储库的主页上的文件列表上方,单击“ commits”****。

    存储库的主页的屏幕截图。 时钟图标和“178 个提交”以橙色边框突出显示。

  3. 若要导航到特定提交,请单击该提交的提交消息。

    存储库提交列表中提交的屏幕截图。 “更新 README.md”以橙色边框突出显示。

  4. Hover over the blue to the right of the username.

  5. Use the message to decide what to update:

    • Unrecognized author (with email address): Add the shown email address to your GitHub account.
    • Unrecognized author (no email address): Set your commit email address in Git, then add that address to your GitHub account.
    • Invalid email: Set a valid commit email address in Git, then add that address to your GitHub account.

Old commits might not be linked after you update your email settings. See 设置提交电子邮件地址.

A commit exists on GitHub but not in your local clone

If git show COMMIT-SHA returns an error locally but the commit is visible on GitHub, your local clone may be out of date or the commit may no longer be referenced by a branch.

The local repository is out of date

Fetch information from the remote repository.

git fetch REMOTE

Use git fetch upstream for a fork's upstream repository, or git fetch origin for the repository you cloned.

The branch that contained the commit was deleted

If the branch was deleted or force pushed, ask a collaborator who still has the commit locally to push it to a new branch.

git branch recover-B B
git push upstream B:recover-B

Then, fetch the recovered branch.

git fetch upstream recover-B

Avoid force pushes

Avoid force pushing unless necessary, especially when more than one person can push to the repository. Force pushing rewrites repository history and can disrupt collaborators or corrupt pull requests.

A commit is blocked by push protection

Push protection blocks commits, uploads, or API requests that contain supported secrets.

Understanding why push protection has blocked your commit

If push protection blocks your work, GitHub detected a supported secret in your commit or request. Remove the secret before trying again.

Resolving a push protection block

  1. Review the push protection message to identify the secret and where it appears.
  2. Remove the secret from the commit, file upload, or API request.
  3. Try the push, commit, upload, or request again.
  4. If you believe the secret is safe to push, follow the bypass steps for your workflow:

Further reading