git pull 后如何查看代码更改?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11284350/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:03:59  来源:igfitidea点击:

How to see code changes after git pull?

git

提问by uwe

I would like to inspect any code changes after doing a git pull. Currently it's just showing me which files changes. How can I see what code changed?

我想在执行git pull. 目前它只是向我显示哪些文件发生了变化。如何查看更改的代码?

回答by Wayne Conrad

git log --name-status -2

Will show you the names of the files that changed for the last two commits.

将显示最近两次提交更改的文件的名称。

git log -p -2

Will show you the changes themselves.

将向您展示变化本身。

Before you pull,

在你拉之前,

git fetch
git log --name-status origin/master..

Will show you what commits you are about to retrieve, along with the names of the files.

将显示您将要检索的提交以及文件的名称。

回答by quornian

Before pulling

拉前

You can review changes as @iblue says with a fetchand diffbefore merging:

在合并之前,您可以像@iblue 所说的那样用 afetch和查看更改diff

$ git fetch
$ git diff master...origin/master

Note the triple period, which means diff against the shared parent and origin/master (commits marked xbelow):

注意三重周期,这意味着与共享父级和源/主控的差异(x下面标记的提交):

SP---o---o [master]
  \
   x---x [origin/master]

Just after a pull

一拉之后

The very first line in the output of a pull looks like this:

pull 输出的第一行如下所示:

$ git pull
Updating 37b431a..b2615b4
...

You can then simply do:

然后你可以简单地做:

$ git diff 37b431a..b2615b4

Or whatever other command:

或任何其他命令:

$ git log --name-status 37b431a..b2615b4

Later on

稍后的

If it has been a while since you pulled, and you wish to know what changes were brought in by the last pull, you can look it up with:

如果您拉取已经有一段时间了,并且您想知道上次拉取带来了哪些更改,您可以通过以下方式查找:

$ git reflog | grep -A1 pull | head -2

which will show the hash after the pull followed by the hash before the pull:

这将显示拉取后的哈希值,然后显示拉取前的哈希值:

b2615b4 HEAD@{0}: pull : Fast-forward
37b431a HEAD@{1}: checkout: moving from v6.1 to master

You can then do the same thing with these two hashes:

然后你可以用这两个散列做同样的事情:

git diff 37b431a..b2615b4

回答by iblue

Because git pullis just a shortcut for git fetchand git merge, you can run git fetchto fetch the branches from the origin and then show the differences before merging. Like this:

因为git pull只是git fetchand 的一个快捷方式git merge,你可以运行git fetch从原点获取分支,然后在合并之前显示差异。像这样:

git fetch                      # Load changes from remote server
git diff master origin/master  # Show differences
git merge origin/master        # Merge remote changes with local changes

If you run on a different branch than master, you should of course change the branch names in the commands above.

如果您在与master不同的分支上运行,您当然应该在上面的命令中更改分支名称。

回答by Kasun

You can compare the pulled contents with the sources of immediately previous commit by,

您可以通过以下方式将提取的内容与上一次提交的来源进行比较,

git diff branch_name@{1}

eg:

例如:

git diff master@{1}

For comparing with the sources n commits behind,

为了与后面的源 n 提交进行比较,

git diff branch_name@{n}

回答by Sandip Karanjekar

You can check what get change while push and pull by this...

你可以通过这个检查在推拉时得到什么改变......

git log --stat