【问题标题】:How to check with git if a file is committed but not pushed如果文件已提交但未推送,如何使用 git 检查
【发布时间】:2022-06-30 21:49:30
【问题描述】:

使用git status --porcelain <file> 我可以检查文件是否 被修改、删除、添加、...

https://git-scm.com/docs/git-status#_short_format

如果文件在本地被修改和提交,git status --porcelain <file> 不会返回任何值。

使用git status <file>,我知道整个 repo 是 x 提前提交,但这是针对整个 repo 而不是仅针对单个文件。

如果单个文件已提交但未推送,我如何检查它。

【问题讨论】:

标签: git


【解决方案1】:

我能想到的一个非常接近的事情:

git fetch

# check if there is a diff on your file between your current version
# and the version in your current commit.
# '@{u}' is a shortcut to "the upstream branch of the current branch"
git diff --name-only @{u} HEAD -- path/to/file

如果您看到文件名,这意味着远程版本和您的本地版本不同。

您可能需要一些额外的步骤来检查差异是否来自:

  • 您的修改“未推送”
  • 其他人在您的基础上进行了额外的修改

【讨论】:

    【解决方案2】:

    您也可以使用git diff --cachedgit status --verbose

    git diff 命令显示工作目录和暂存区之间的变化。

    运行git status 命令显示工作目录和暂存区的状态。

    --verbose 选项不仅显示已更改文件的名称,还显示暂待提交的文本更改。

    【讨论】:

      猜你喜欢
      • 2011-04-27
      • 2013-12-11
      • 2011-01-02
      • 2013-12-17
      • 2013-07-28
      • 2013-02-13
      • 2022-05-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多