How do I get the list of files about to be updated by `git pull` without knowing the branch name or what it tracks?

前端 未结 2 1770
说谎
说谎 2021-01-01 18:04

How do I get the list of files that are about to be updated (or were just updated) by git pull so i can parse them and take appropriate action in a script?

相关标签:
2条回答
  • 2021-01-01 18:21

    A more generic solution than @obmarg's answer is this:

    git fetch && git diff --name-only @ @{u}
    

    Here @ is a shortcut for HEAD which in turn is a pointer to your currently checked out branch. @{u} or @{upstream} denotes the tracking branch for HEAD. So no hardcoded assumptions about the current branch (master), the name of the remote (origin) or the name of the tracking branch (origin/master) is necessary.

    If you want to do this with another branch, use this:

    git fetch && git diff --name-only master master@{u}
    

    The syntax for @{u} is explained in git help revisions, search for upstream.

    0 讨论(0)
  • 2021-01-01 18:41

    Assuming you know the name of the remote (in my examples, origin) then you could simply go:

    git fetch && git diff --name-only ..origin
    
    templates/shows/showBase.html
    templates/shows/showList.html
    templates/shows/showListEntry.htm
    

    Or if you wanted to sort into individual commits, you could use whatchanged:

    git fetch && git whatchanged --name-only ..origin
    
    commit fcb1b56d564fe85615ecd6befcd82f6fda5699ae
    Author: Grambo <email@email>
    Date:   Mon Dec 12 23:36:38 2011 +0000
    
        Hooked "I've Seen This" button up to "Review Show" dialog
    
    templates/shows/showBase.html
    templates/shows/showList.html
    templates/shows/showListEntry.htm
    
    commit xasdasdsada......
    
    0 讨论(0)
提交回复
热议问题