我可以列出当前提交的文件吗?

May I list the files of the current commit?

想象一下,每次我提交文件时,在推送它们之前,我想列出它们以供检查。我该怎么做?

我试过:

git ls-tree -r --name-only master
git ls-files -stage

如果我编辑单个文件,add 然后 commit 它。如果我尝试上面的代码,它会显示我所有的文件。

我只想列出将在当前提交上推送的文件。

如果你想列出最后一次提交(本地或非本地)的文件,使用这个

git show --name-only

Git diff 来解决这个问题。您将使用 --name-only 标志。要获取当前提交的内容,请使用此命令:

#before stage
  git diff --name-only 
#staged changes before committing
  git diff --name-only --cached
#after committing
  git diff --name-only HEAD^ HEAD

如果你想在有多个提交的情况下看到你将推送的文件,你需要指定你当前的分支头和远程头

git diff --name-only remote/branch branch

正如你在推送之前所说的,我可以假设你的工作流程是 git 添加然后 git 提交然后 git 推送。

您可以使用 --short 选项进行提交 link!

这将为您提供当前提交中所有文件更改、添加或删除的输出。

git commit --short -m "message for the commit"