0

My CI environment only has the branch being pushed. Is it possible to see all files that have changed since the creation of the branch without comparing it to another branch?

I found multiple examples comparing branches, but nothing that worked when only one branch is available.

I'm trying to think outside the box, like number of commits with the branch name then get that many commits from the log like such where -n would be the number of commits:

git log --name-only --pretty=format: -n 5 | sed '/^$/d' | uniq

but I cannot find a way to get the correct number of commits

badger0053
  • 1,179
  • 1
  • 13
  • 19
  • 1
    Branches do not have a creation point. They are merely a human-readable name for a single commit hash. (The set of branches that contain any given commit changes dynamically, and many commits are on many branches simultaneously.) To compare two commits, you need two commit hashes, which means you'll need another name or similar. See also https://stackoverflow.com/q/3161204/1256452 – torek Aug 23 '18 at 01:10
  • @torek that makes sense. I think I'll have to use a combination of git and bash to get what I want. Do you know of a way to get a list of all the commit hashes with their branch name? Even if I have to go to look through all commits I would be able to grep from there – badger0053 Aug 23 '18 at 12:53
  • 1
    `git rev-list ` lists all commits reachable from the given starting point, but that's not really very useful since so many commits are reachable from *every* starting point. Meanwhile if you want to translate each branch name to its corresponding hash ID—this is more useful, but still won't really get you what you want—see `git for-each-ref` for scripting, and remember that branch names are specifically those references in the `refs/heads/*` namespace. [continued] – torek Aug 23 '18 at 15:05
  • 1
    [cont'd] I believe that what you are doing is going down the "all commits reachable from this branch but not any other branch" rathole, i.e., `git rev-list --not `. This method *works* ... for some limited use cases, but it's terribly fragile, because, well, see the linked question! Basically it breaks as soon as soon as someone starts getting clever with branch names. (The correct tool in a CI system is to mark your start-point, perhaps with a name in a name-space you make up specifically for your CI system.) – torek Aug 23 '18 at 15:08

1 Answers1

1

git log - include the initial commit

/mnt/c/git/ConsoleApp1 (master)>git log --name-only --oneline --pretty=format: | sort | uniq

ConsoleApp1/Class1.cs
ConsoleApp1/ConsoleApp1.csproj
ConsoleApp1/Program.cs
ConsoleApp1.sln
.gitignore
x.txt
z.txt

git diff-tree Not including the first commit

  1. Find the first commit e.g. git rev-list or git log
  2. git diff-tree

    C:\git\ConsoleApp1>git diff-tree --no-commit-id --name-only -r 2f6e395..HEAD
    ConsoleApp1/Class1.cs
    x.txt
    z.txt
    

git show - including first commit

  1. Find the first commit e.g. git rev-list or git log
  2. git show - please note that git show is a porcelain command and it's not meant for scripting

    C:\git\ConsoleApp1>git show --name-only --pretty="" -r 2f6e395..HEAD && git show --name-only --pretty="" -r 2f6e395
    z.txt
    x.txt
    ConsoleApp1/Class1.cs
    .gitignore
    ConsoleApp1.sln
    ConsoleApp1/ConsoleApp1.csproj
    ConsoleApp1/Program.cs
    
tymtam
  • 31,798
  • 8
  • 86
  • 126
  • Thanks for taking the time to come up with these examples. Each of them, unfortunately, is either showing me too much (the first example give me thousands of files) or too little (the last two didn't show me all files that have changed) – badger0053 Aug 23 '18 at 12:59
  • Yes, all these methods got to the root of the repo - I understood that's what you wanted – tymtam Aug 23 '18 at 23:45