Git pull后的细节变化
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1362952/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Detail change after Git pull
提问by Tim
After a Git pull, its output gives a summary on the change amount.
在 Git 拉取后,其输出会给出更改量的摘要。
How can I see each or some of the files detailed changes?
如何查看每个或某些文件的详细更改?
Okay, here is my question to Jefromi:
好的,这是我对 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
?
我怎么知道我是否正在拉到主人?我所做的只是“git pull”。
master 指向什么,master 和 HEAD 这两个 Git 默认的 head 有什么区别?
如何查看特定文件中的详细更改?
我如何
git pull
再次看到最后一次汇总输出的变化?有什么区别
git diff
和git whatchanged
?
回答by Cascabel
Suppose you're pulling to master. You can refer to the previous position of master
by master@{1}
(or even master@{10.minutes.ago}
; see the specifying revisions section of the git-rev-parse man page), so that you can do things like
假设你正在拉到主人。您可以参考master
by master@{1}
(甚至master@{10.minutes.ago}
; 请参阅git-rev-parse 手册页的指定修订部分)的先前位置,以便您可以执行以下操作
See 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
查看所有更改:
git diff master@{1} master
查看给定文件的更改:
git diff master@{1} master <file>
查看给定目录中的所有更改:
git diff master@{1} master <dir>
再次查看更改摘要:
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 of git status
. I highly recommend skimming the man pages of commands to use - it's a great way to slowly pick up some knowledge.
至于你的“我怎么知道我是否在 master 上”的问题……嗯,使用分支是 Git 工作流程的重要组成部分。您应该始终了解您所在的分支 - 如果您拉取更改,您希望将它们拉到正确的分支!您可以使用命令查看所有分支的列表,当前签出的分支带有星号git branch
。当前分支名称也与输出一起打印git status
。我强烈建议您浏览要使用的命令的手册页 - 这是慢慢获取一些知识的好方法。
And your last question: HEAD
is the name for the currently checked out branch. You can indeed use HEAD
and HEAD@{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, and HEAD@{1}
is now master
- not what you want!
你的最后一个问题:HEAD
是当前签出分支的名称。您确实也可以在这种情况下使用HEAD
and HEAD@{1}
,但是使用分支会更健壮一些,因为如果您去检查另一个分支。HEAD
现在是第二个分支,HEAD@{1}
现在master
- 不是你想要的!
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 教程。网络上有一百万,例如:
- The Pro Git book
- Git Magic
- and the 4.5 million hits on Google for "Git tutorial"
回答by Christian Oudard
Say you do a git pull like this:
假设你像这样执行 git pull:
$ git pull
remote: Counting objects: 10, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 6 (delta 4), reused 0 (delta 0)
Unpacking objects: 100% (6/6), done.
From [email protected]:reponame
a407564..9f52bed branchname -> origin/branchname
Updating a407564..9f52bed
Fast forward
.../folder/filename | 209 ++++++++-----
.../folder2/filename2 | 120 +++++++++++---------
2 files changed, 210 insertions(+), 119 deletions(-)
You can see the diff of what changed by using the revision numbers:
您可以使用修订号查看更改内容的差异:
$ git diff a407564..9f52bed
回答by kaiser
1.How do I know if I was pulling to master? All I did is "git pull".
1.我怎么知道我是否在拉到大师?我所做的只是“git pull”。
The command itself works like this:
命令本身的工作方式如下:
git pull [options] [<repository> [<refspec>…]]
and per default refers to the current branch. You can check your branches by using
并且默认是指当前分支。您可以使用
git branch -a
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)
这将列出您的本地和远程分支,例如(---
在本地和远程之间添加一个分隔符以使其更清晰)
*master
foo
bar
baz
---
origin/HEAD -> origin/master
origin/deploy
origin/foo
origin/master
origin/bar
remote2/foo
remote2/baz
When you then take a look at one remote repo, you will see what you are referring to:
当您查看一个远程存储库时,您将看到您所指的内容:
git remote show origin
will list like the following:
将列出如下:
* remote origin
Fetch URL: ssh://[email protected]:12345/username/somerepo.git
Push URL: ssh://[email protected]:12345/username/somerepo.git
HEAD branch: master
Remote branches:
foo tracked
master tracked
Local refs configured for 'git push':
foo pushes to foo (up to date)
master pushes to master (fast-forwardable)
So it's quite easy to be sure where to pull from and push to.
所以很容易确定从哪里拉到哪里。
3.how to see the detail change in a specific file?
4.how to see the change in summary output by last git pull again?
3.如何查看特定文件中的细节变化?
4.如何再次查看上次git pull的summary输出的变化?
The easiest and most elegant way(imo) is:
最简单和最优雅的方式(imo) 是:
git diff --stat master@{1}..master --dirstat=cumulative,files
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):
这将为您提供有关上次拉取当前工作状态之间更改的两个信息块。示例输出(我---
在--stat
和--dirstat
输出之间添加了一个分隔符以使其更清晰):
mu-plugins/media_att_count.php | 0
mu-plugins/phpinfo.php | 0
mu-plugins/template_debug.php | 0
themes/dev/archive.php | 0
themes/dev/category.php | 42 ++++++++++++++++++
.../page_templates/foo_template.php | 0
themes/dev/style.css | 0
themes/dev/tag.php | 44 +++++++++++++++++++
themes/dev/taxonomy-post_format.php | 41 +++++++++++++++++
themes/dev/template_parts/bar_template.php | 0
themes/someproject/template_wrappers/loop_foo.php | 51 ++++++++++++++++++++++
---
11 files changed, 178 insertions(+)
71.3% themes/dev/
28.6% themes/someproject/template_wrappers/
100.0% themes/
27.2% mu-plugins/
9.0% themes/dev/page_templates/
9.0% themes/dev/template_parts/
63.6% themes/dev/
9.0% themes/someproject/template_wrappers/
72.7% themes/
回答by Hyman
This way's kind of hacky, but it'll allow you to use graphical tools like gitk
or gitg
or git-gui
:
这样的样哈克,但它会允许你使用图形化的工具,如gitk
或gitg
或git-gui
:
git pull
git reset HEAD@{1}
gitg (or gitk or whatever tool you like)
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
获得最高票数的答案给出了使用 git 工具的最佳方法,但我使用这种方法是因为我可以使用带有 GUI 的工具来查看更改:P
I'd then have the extra step of doing a git checkout .
and then doing git 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.
然后我会有一个额外的步骤,git checkout .
然后再做git pull
一次,以便我正确地拉取和合并,但我重视检查 GUI 中差异的能力,足以处理额外的两个步骤。