Git pull 后的详细更改
Git 拉取后,其输出会给出更改量的摘要。
如何查看每个或部分文件的详细更改?
好的,这是我向 Jefromi 提出的问题:
我如何知道我是否正在拉向大师?我所做的只是“git pull”。
master 指向什么,git 的两个默认头 master 和 HEAD 之间有什么区别?
master 指向什么,git如何查看特定文件中的详细更改?
如何再次查看上次
如何git pull
的摘要输出中的更改?git diff
和git Whatchanged
之间有什么区别?
After a Git pull, its output gives a summary on the change amount.
How can I see each or some of the files detailed changes?
Okay, here is my question to Jefromi:
How do I know if I was pulling to master? All I did is "git pull".
What does master point to and what is the difference between master and HEAD, the two default heads of Git?
How do I see the detailed change in a specific file?
How do I see the change in the summary output by the last
git pull
again?What's difference between
git diff
andgit whatchanged
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
假设你正在拉向大师。您可以通过
master@{1}
(甚至master@{10.mines.ago}
)引用master
的先前位置;请参阅git-rev-parse 的指定修订部分手册页),以便您可以执行以下操作:查看所有更改:
git diff master@{1} master
查看给定文件的更改:
git diff master@{1} master
查看给定目录内的所有更改:
git diff master@{1} master <
dir>再次查看更改摘要:
>git diff --stat master@{1} master
至于您的问题“我怎么知道我是否在 master 上”……嗯,使用分支是 Git 工作流程的重要组成部分。您应该始终知道您所在的分支 - 如果您拉取了更改,您希望将它们拉到正确的分支!您可以使用命令
gitbranch
查看所有分支的列表,当前签出的分支带有星号。当前分支名称也会与 git status 的输出一起打印。我强烈建议浏览要使用的命令的手册页 - 这是慢慢学习一些知识的好方法。最后一个问题:
HEAD
是当前签出分支的名称。您确实也可以在这种情况下使用HEAD
和HEAD@{1}
,但是使用分支会更稳健一些,因为如果您去查看另一个分支分支。HEAD
现在是第二个分支,而HEAD@{1}
现在是master
- 这不是您想要的!为了避免问很多这样的小问题,您可能应该看看 Git 教程。网络上有一百万本,例如:
Suppose you're pulling to master. You can refer to the previous position of
master
bymaster@{1}
(or evenmaster@{10.minutes.ago}
; see the specifying revisions section of the git-rev-parse man page), so that you can do things likeSee all of the changes:
git diff master@{1} master
See the changes to a given file:
git diff master@{1} master <file>
See all the changes within a given directory:
git diff master@{1} master <dir>
See the summary of changes again:
git diff --stat master@{1} master
As for your question of "how do I know if I'm on master"... well, using branches is an important part of the Git workflow. You should always be aware of what branch you're on - if you pulled changes, you want to pull them to the right branch! You can see a list of all branches, with an asterisk by the currently checked-out one, with the command
git branch
. The current branch name is also printed along with the output ofgit status
. I highly recommend skimming the man pages of commands to use - it's a great way to slowly pick up some knowledge.And your last question:
HEAD
is the name for the currently checked out branch. You can indeed useHEAD
andHEAD@{1}
in this context as well, but it's a bit more robust to use the branches, since if you go and check out another branch.HEAD
is now that second branch, andHEAD@{1}
is nowmaster
- not what you want!To save having to ask a lot of little questions like this, you should probably have a look at a Git tutorial. There are a million on the web, for example:
假设您执行如下 git pull 操作:
您可以使用修订号查看更改内容的差异:
Say you do a git pull like this:
You can see the diff of what changed by using the revision numbers:
该命令本身的工作原理如下:
默认情况下指的是当前分支。您可以使用检查您的分支
这将列出您的本地和远程分支,例如(添加了
---
作为本地和远程之间的分隔符以使其更加清晰)当您看一下时在一个远程存储库中,您将看到您所指的内容:
将列出如下所示:
因此很容易确定从哪里拉取和推送到哪里。
最简单且最优雅的方式(imo)是:
这将为您提供有关上次拉取和当前工作状态之间的变化的两个信息块。示例输出(我在
--stat
和--dirstat
输出之间添加了---
作为分隔符,以使其更加清晰):The command itself works like this:
and per default refers to the current branch. You can check your branches by using
This will list your local and remote branches like for e.g so (Added a
---
as divider between local and remote to make it more clear)When you then take a look at one remote repo, you will see what you are referring to:
will list like the following:
So it's quite easy to be sure where to pull from and push to.
The easiest and most elegant way (imo) is:
This will give you two blocks of information about the changes in between your last pull an the current state of work. Example output (I added a
---
as divider between--stat
and--dirstat
output to make it more clear):这种方式有点 hacky,但它允许您使用 gitk 或 gitg 或 git-gui 等图形工具:
答案是大多数赞成给出了使用 git 工具的最佳方法,但我使用这种方法是因为我可以利用带有 GUI 的工具来查看更改:P 然后
我需要执行 git checkout 的额外步骤。 然后再次执行 git pull 以便正确拉取和合并,但我很看重检查 GUI 中差异的能力,足以处理额外的两个步骤。
This way's kind of hacky, but it'll allow you to use graphical tools like
gitk
orgitg
orgit-gui
:The answer with the most upvotes gives the best way using the git tool, but I use this method because I can then utilize tools with GUI to see the changes :P
I'd then have the extra step of doing a
git checkout .
and then doinggit pull
again so that I properly pull and merge, but I value the ability to examine differences in a GUI enough to deal with the extra two steps.