Get all files that have been modified in git branch

后端 未结 16 1603
深忆病人
深忆病人 2020-12-02 04:14

Is there a way to see what files have changed in a branch?

相关标签:
16条回答
  • 2020-12-02 04:51

    The following batch file is based on twalberg's answer but will work in Windows:

    @ECHO OFF
    C:                               :: <== OR USE A DIFFERENT DRIVE
    CD \path\to\where\git\files\are  :: <== CHANGE TO THE ACTUAL PATH
    SET /p b="Enter full path of an ALREADY MERGED branch to compare with origin/master: "
    bash --login -i -c "git diff --name-only %b% $(git merge-base %b1% origin/drop2/master)"
    PAUSE
    

    The above assumes that the main branch is origin/master and that git bash was included when Git was installed (and its location is in the path environment). I actually needed to show the actual differences using a configured diff tool (kdiff3) so substituted the following bash command above:

    bash --login -i -c "git difftool --dir-diff %b% $(git merge-base %b1% origin/drop2/master)"
    
    0 讨论(0)
  • 2020-12-02 04:53

    An alternative to the answer by @Marco Ponti, and avoiding the checkout:

    git diff --name-only <notMainDev> $(git merge-base <notMainDev> <mainDev>)
    

    If your particular shell doesn't understand the $() construct, use back-ticks instead.

    0 讨论(0)
  • 2020-12-02 04:54

    Update Nov 2020:

    To get the list of files modified (and committed!) in the current branch you can use the shortest console command using standard git:

    git diff --name-only master...


    • If your local "master" branch is outdated (behind the remote), add a remote name (assuming its "origin") git diff --name-only origin/master...

    • If you want to include uncommitted changes as well, remove the ...:

      git diff --name-only master

    • If you use different main branch name (eg: "main"), substitute it:

      git diff --name-only origin/main...

    • If your want to output to stdout (so its copyable)

      git diff --name-only master... | cat


    per really nice detailed explanation of different options https://blog.jpalardy.com/posts/git-how-to-find-modified-files-on-a-branch/

    0 讨论(0)
  • 2020-12-02 04:55
    git show --stat origin/branch_name
    

    This will give you a list of the files that have been added or modified under this branch.

    0 讨论(0)
提交回复
热议问题