简体   繁体   English

Git:查看我的最后一次提交

[英]Git: See my last commit

I just want to see the files that were committed in the last commit exactly as I saw the list when I did git commit .我只想查看上次提交中提交的文件,就像我在执行git commit时看到的列表一样。 Unfortunately searching for不幸的是寻找

git "last commit" log

in Google gets me nowhere.在谷歌让我无处可去。 And

git diff HEAD^..HEAD

is not what I need, of course, since it spews the guts of the change too.当然,这不是我需要的,因为它也吐出了变化的内脏。

As determined via comments, it appears that the OP is looking for根据评论确定,OP 似乎正在寻找

$ git log --name-status HEAD^..HEAD

This is also very close to the output you'd get from svn status or svn log -v , which many people coming from subversion to git are familiar with.这也非常接近您从svn statussvn log -v获得的输出,许多从 subversion 转为 git 的人都熟悉它。

--name-status is the key here; --name-status是这里的关键; as noted by other folks in this question, you can use git log -1 , git show , and git diff to get the same sort of output.正如其他人在这个问题中所指出的,您可以使用git log -1git showgit diff来获得相同类型的输出。 Personally, I tend to use git show <rev> when looking at individual revisions.就个人而言,我倾向于在查看个别修订时使用git show <rev>

Use git show :使用git 显示

git show --summary

This will show the names of created or removed files, but not the names of changed files.这将显示已创建或已删除文件的名称,但不会显示已更改文件的名称。 The git show command supports a wide variety of output formats that show various types of information about commits. git show命令支持多种输出格式,可以显示有关提交的各种类型的信息。

git log -1 --stat

可以工作

By far the simplest command for this is:到目前为止,最简单的命令是:

git show --name-only

As it lists just the files in the last commit and doesn't give you the entire guts由于它列出只是在最后的文件提交,不给你整胆

An example of the output being:输出的一个例子是:

commit  fkh889hiuhb069e44254b4925d2b580a602
Author: Kylo Ren <Kylo@darkside.empire.gov>
Date:   Sat May 4 16:50:32 2168 -0700

Changed shield frequencies to prevent Millennium Falcon landing

 www/controllers/landing_ba_controller.js             
 www/controllers/landing_b_controller.js            
 www/controllers/landing_bp_controller.js          
 www/controllers/landing_h_controller.js          
 www/controllers/landing_w_controller.js  
 www/htdocs/robots.txt                        
 www/htdocs/templates/shields_FAQ.html       

To see last commit查看上次提交

git log -1

To see last 2 commit查看最后 2 次提交

git log -2

etc....等等....

To see last commit changes查看上次提交更改

git show HEAD

Or to see second last commit changes或者查看倒数第二次提交更改

git show HEAD~1

And for further just replace '1' in above with the required commit sequence number.为了进一步,只需将上面的“1”替换为所需的提交序列号。

git log -1 --name-status

对我有用。

After you do several commits or clone/pull a repository, you might want to see what commits have been made.在您进行多次提交或克隆/拉取存储库后,您可能想查看已进行的提交。 Just check these simple solutions to see your commit history (from last/recent commit to the first one).只需检查这些简单的解决方案即可查看您的提交历史记录(从上次/最近提交到第一个提交)。

For the last commit, just fire this command: git log -1 .对于最后一次提交,只需触发以下命令: git log -1 For more interesting things see below -更多有趣的事情见下文——

  1. To see the commit ID (SHA-1 checksum), Author name <mail ID>, Date along with time, and commit message -要查看提交 ID(SHA-1 校验和)、作者姓名 <邮件 ID>、日期和时间以及提交消息 -

     git log
  2. To see some more stats, such as the names of all the files changed during that commit and number of insertions/deletions.要查看更多统计信息,例如在该提交期间更改的所有文件的名称以及插入/删除的数量。 This comes in very handy while reviewing the code -这在审查代码时非常方便 -

     git log --stat
  3. To see commit histories in some pretty formats :) (This is followed by some prebuild options)-以一些漂亮的格式查看提交历史:)(后面是一些预构建选项)-

    • If you have too many commits to review, this command will show them in a neat single line:如果你有太多的提交需要审查,这个命令会将它们显示在一个整洁的单行中:

       git log --pretty=oneline
    • To see short, medium, full, or even more details of your commit, use following, respectively -要查看提交的简短、中等、完整甚至更多详细信息,请分别使用以下内容 -

       git log --pretty=short git log --pretty=medium git log --pretty=full git log --pretty=fuller
  4. You can even use your own output format using the format option -您甚至可以使用format选项使用自己的输出格式 -

     git log --pretty=format:"%an, %ae - %s"

    where %an - author name, %ae - author email, %s - subject of commit, etc.其中 %an - 作者姓名,%ae - 作者电子邮件,%s - 提交主题等。

This can help you with your commit histories.这可以帮助您处理提交历史记录。 For more information, click here .如需更多信息,请单击此处

$ git diff --name-only HEAD^..HEAD

or或者

$ git log --name-only HEAD^..HEAD

git diff --stat HEAD

这显示了与您上次提交相同的 diffstat。

This question is already answered above which states the file names in last commit by git log / other commands.上面已经回答了这个问题,它说明了 git log / 其他命令在上次提交中的文件名。 If someone wants to see what all changed in last commit (line differences), you can use this command -如果有人想查看上次提交中的所有更改(行差异),您可以使用此命令 -

git show

This automatically displays the line differences in last commit.这会自动显示上次提交中的行差异。

Like git log -1 --stat you can use git show --stat .git log -1 --stat你可以使用git show --stat

Another way to list only the files is to use:仅列出文件的另一种方法是使用:
git diff-tree --no-commit-id --name-only -r HEAD^..HEAD
Or you can use any two commit IDs或者您可以使用任意两个提交 ID

You can run你可以跑

 git show --source

it shows the author, Date, the commit's message and the diff --git for all changed files in latest commit.它显示了作者、日期、提交的消息和最新提交中所有更改文件的diff --git

If you're talking about finding the latest and greatest commit after you've performed a git checkout of some earlier commit ( and forgot to write down HEAD's hash prior to executing the checkout ) most of the above won't get you back to where you started.如果您正在讨论在对一些较早的提交执行 git checkout并且在执行 checkout 之前忘记写下 HEAD 的哈希值之后找到最新和最大的提交,那么上面的大部分内容都不会让您回到哪里你开始了。 git log -[some #] only shows the log from the CURRENT position of HEAD , which is not necessarily the very last commit (state of the project). git log -[some #]只显示HEAD 当前位置的日志,这不一定是最后一次提交(项目状态)。 Checkout will disconnect the HEAD and point it to whatever you checked out. Checkout 将断开 HEAD 并将其指向您签出的任何内容。

You could view the entire git reflog , until reaching the entry referencing the original clone.您可以查看整个git reflog ,直到到达引用原始克隆的条目。 BTW, this too won't work if any commits were made between the time you cloned the project and when you performed a checkout.顺便说一句,如果在您克隆项目和执行签出之间进行了任何提交,这也将不起作用。 Otherwise you can hope all your commits on your local machine are on the server, and then re-clone the entire project.否则你可以希望你在本地机器上的所有提交都在服务器上,然后重新克隆整个项目。

Hope this helps.希望这可以帮助。

if you want to see just the name of files in the last commit如果您只想查看上次提交中的文件名

 git diff HEAD@{1} --name-only

if you want also to see the content changes remove the --name-only如果您还想查看内容更改,请删除--name-only

if you want to compare current state with older commits, increase the {n}如果要将当前状态与较旧的提交进行比较,请增加{n}

在 git 中单独获取我的最后一次提交消息

git log --format=%B -n 1 $(git log -1 --pretty=format:"%h") | cat -

查看之前的提交 SHA

git log -n 2 --pretty=format:"%h" | tail -n 1

and without git: tail -n1 .git/logs/HEAD | cut -d' ' -f1,8-并且没有 git: tail -n1 .git/logs/HEAD | cut -d' ' -f1,8- tail -n1 .git/logs/HEAD | cut -d' ' -f1,8-

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM