简体   繁体   English

在拉之前得到最后一次提交的sha

[英]Get sha of the last commit before pull

After pull, git lists the files modified since the last pull. 拉后,git列出自上次拉取后修改的文件。

The question is, how to get this list after some more work was done on local repo. 问题是,如何在本地回购完成更多工作后获取此列表。

eg 例如

$ git checkout feature/default2
$ git pull
Updating 5420c70..b8eec49
Fast-forward
 application/configs/application.ini                                 |   1 +
 application/modules/product/forms/Search.php                        |   3 ++
 public/themes/default/bootstrap/buttons.less                        |  25 -----------
 public/themes/default/css/cmspanel.css                              | 234 ++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------
 public/themes/default/css/products.css                              |  57 ++++++++++++++++++++----
 public/themes/default/css/style.css                                 | 270 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------
 public/themes/default/gfx/icons/menu-drop-dark.png                  | Bin 0 -> 160 bytes
 public/themes/default/gfx/icons/more.png                            | Bin 0 -> 120 bytes
 public/themes/default/layouts/scripts/footer.phtml                  |  26 ++++++++++-
 public/themes/default/layouts/scripts/gallery.phtml                 |   2 +
 public/themes/default/layouts/scripts/home.phtml                    |   2 +
 public/themes/default/layouts/scripts/layout.phtml                  |   2 +
 public/themes/default/layouts/scripts/products.phtml                |  22 ++++-----
 public/themes/default/less/cmspanel.less                            |  26 +++++++++++
 public/themes/default/less/nav.less                                 |   4 +-
 public/themes/default/less/products.less                            |  61 +++++++++++++++++++++----
 public/themes/default/less/style.less                               |  59 ++++++++++++++++++++++---
 public/themes/default/less/widgets.less                             |  37 +++++++++++++++-
 public/themes/default/modules/cms/scripts/widgets/random.phtml      |   6 +--
 public/themes/default/modules/default/scripts/widgets/submenu.phtml |   2 +-
 public/themes/default/modules/product/scripts/index/view.phtml      |  44 +++++++++---------
 public/themes/default/modules/product/scripts/widgets/search.phtml  |  16 +++++++
 22 files changed, 584 insertions(+), 315 deletions(-)
 create mode 100644 public/themes/default/gfx/icons/menu-drop-dark.png
 create mode 100644 public/themes/default/gfx/icons/more.png

The 5420c70 is the state before pull. 5420c70是拉前的状态。
How to determine that 5420c70 sha? 怎么判断5420c70沙?

If I'm correct, the ORIG_HEAD is the state before the last pull (any pull, not the pull which introduced some changes). 如果我是正确的,ORIG_HEAD是最后一次拉动之前的状态(任何拉动,而不是引入一些变化的拉力)。

Im looking for some magic alias like git checkout SOME_HEAD to do git checkout 5420c70 for me. 进出口寻找一些神奇的别名像git checkout SOME_HEADgit checkout 5420c70我。

I'm trying to setup a git review alias, which should diff all the files modified since the last pull, which was not up-to-date. 我正在尝试设置一个git review别名,它应该区分自上次拉动以来修改的所有文件,这些文件不是最新的。

In a basic case, something like this works: 在一个基本情况下,这样的工作:

git pull
# lists some chanes file
git diff --name-status ORIG_HEAD..
# diffs them

but I'm looking for something like this: 但我正在寻找这样的东西:

git pull
# lists some chanes file
git pull
# up-to-date, no changes
git diff --name-status ORIG_HEAD..
# diffs the files since the last pull which was not up-to-date

I think you could check reflog, ie HEAD@{1} , eg it diff --name-only ..HEAD@{1} . 我想你可以检查reflog,即HEAD@{1} ,例如diff --name-only ..HEAD@{1}

As another option, you could do git fetch then do git log -p ..@{upstream} to see upcoming changes, and then git merge FETCH_HEAD to bring the changes into your working copy. 作为另一种选择,您可以执行git fetch然后执行git log -p ..@{upstream}查看即将发生的更改,然后git merge FETCH_HEAD将更改带入您的工作副本。

After looking in the reflog, I've found that this is what I was looking for: 在查看reflog之后,我发现这就是我要找的东西:

git reflog --oneline | grep -m 1 "pull " | cut -d' ' -f1)

This will return just one sha of the previous successfull pull, which may be used in show , log , diff etc. 这将只返回上一次成功拉动的一个sha,可以在showlogdiff等中使用。

If i understand what you want, git pull isnt the command you need, You should look at git fetch 如果我明白你想要什么, git pull不是你需要的命令,你应该看看git fetch

when that has completed you can do 完成后你可以做到

git diff HEAD...origin note you need 3 dots instead of the usual 2 git diff HEAD...origin注意你需要3个点而不是通常的2个点

That will give a single diff of all changes. 这将给出所有变化的单一差异。 When your happy you can merge them in the usual way with git merge or by using git cherry-pick to select only certain ones 当你高兴你可以通过git merge以常规方式合并它们,或者使用git cherry-pick来仅选择某些

git log -n 1 --pretty=format:%H

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

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