-1

I went through this [SO OP][1], but wasn't of any help.

I am trying to sort the git branches by creatordate. When I run git branch --sort=creatordate, the displayed list is fine and makes sense as it displays in ascending order of date(most recent branch displayed at last),

user@home MINGW64 /c/Practice-Projects/react (Testing-Interactive-Mode)
    $ git branch --sort=creatordate
      master
      conditional-rendering
      array-destructuring
      useState-Hook
      useEffect-Hook
      useReducer-Hook
      Fetching-Data-With-Hooks
      Displaying-Data-From-An-API
      Handling-Loading-States
      Using-Create-React-App-As-Testing-Platform
      Testing-Small-Functions-With-Jest
      Introducing-React-Testing-Library
    * Testing-Interactive-Mode


    user@root MINGW64 /c/Practice-Projects/react (Testing-Interactive-Mode)
    $ git branch -m Configuring-The-Router


    user@root MINGW64 /c/Practice-Projects/react (Configuring-The-Router)
    $ git branch --sort=creatordate
      master
      conditional-rendering
      array-destructuring
      useState-Hook
      useEffect-Hook
      useReducer-Hook
      Fetching-Data-With-Hooks
      Displaying-Data-From-An-API
      Handling-Loading-States
      Using-Create-React-App-As-Testing-Platform
      Testing-Small-Functions-With-Jest
    * Configuring-The-Router
      Introducing-React-Testing-Library

As can be seen from the above, the sort-order changes(the newly renamed branch Configuring-The-Router became second latest from the latest in order) after I rename the current branch(Testing-Interactive-Mode). I am not sure what is the reason behind such a behavior.

UPDATE 1 : START

I have also tried committerdate, authordate , yet got same results.

user@home MINGW64 /c/Practice-Projects/react (Testing-Interactive-Mode)
$ git branch --sort=creatordate
  master
  conditional-rendering
  array-destructuring
  useState-Hook
  useEffect-Hook
  useReducer-Hook
  Fetching-Data-With-Hooks
  Displaying-Data-From-An-API
  Handling-Loading-States
  Using-Create-React-App-As-Testing-Platform
  Testing-Small-Functions-With-Jest
  Introducing-React-Testing-Library
* Testing-Interactive-Mode


user@root MINGW64 /c/Practice-Projects/react (Testing-Interactive-Mode)
$ git branch -m Configuring-The-Router


user@root MINGW64 /c/Practice-Projects/react (Configuring-The-Router)
$ git branch --sort=creatordate
  master
  conditional-rendering
  array-destructuring
  useState-Hook
  useEffect-Hook
  useReducer-Hook
  Fetching-Data-With-Hooks
  Displaying-Data-From-An-API
  Handling-Loading-States
  Using-Create-React-App-As-Testing-Platform
  Testing-Small-Functions-With-Jest
* Configuring-The-Router
  Introducing-React-Testing-Library

user@root MINGW64 /c/Practice-Projects/react (Configuring-The-Router)
$ git branch --sort=authordate
  master
  conditional-rendering
  array-destructuring
  useState-Hook
  useEffect-Hook
  useReducer-Hook
  Fetching-Data-With-Hooks
  Displaying-Data-From-An-API
  Handling-Loading-States
  Using-Create-React-App-As-Testing-Platform
  Testing-Small-Functions-With-Jest
* Configuring-The-Router
  Introducing-React-Testing-Library

UPDATE 1 : END

Asif Kamran Malick
  • 2,409
  • 3
  • 25
  • 47
  • does this help https://stackoverflow.com/a/5188364/13126651 – Jatin Mehrotra Feb 28 '21 at 15:29
  • @JatinMehrotra, I was looking for the reason why the sort order changes in my case. It doesnot explain anything about the behavior/side-effects of the command – Asif Kamran Malick Feb 28 '21 at 15:48
  • Perhaps you should sort by `committerdate` instead of `creatordate` (though they should be equivalent in this case)? You could also use `--format` to show the value of the field it is sorting on. It's possible that in this case, there is a tie when sorting by `creatordate` alone. – Hasturkun Feb 28 '21 at 15:53
  • I have updated my OP to demonstrate that I did try different combinations of the command. How can there be tie, when the branches were created at different times. – Asif Kamran Malick Feb 28 '21 at 16:05
  • I don’t think branches hold this sort of information? Isn’t it the commit underneath that does? – evolutionxbox Feb 28 '21 at 16:41
  • Reasonable question, voting to close as unreproducible per comments. – jthill Mar 01 '21 at 18:38

1 Answers1

4

If both tips point to the same commit, the sort order is either arbitrary or uses a secondary key (like for instance the branch name).

To see (and show) the dates you're sorting on, try

git log --no-walk --branches --date=iso --pretty=%cd\ %D
jthill
  • 55,082
  • 5
  • 77
  • 137
  • Thanks for responding but, in my case `Introducing-React-Testing-Library` and `Configuring-The-Router` both point to different parent commits. I have confirmed this by reviewing the commit ids and also visualizations. – Asif Kamran Malick Feb 28 '21 at 17:30
  • Though this doesn't resonate with me, this answer is still helpful. – Asif Kamran Malick Feb 28 '21 at 17:48
  • 1
    Okay. Try `git log --no-walk --branches --date=iso --pretty=%cd\ %d` to see the dates. – jthill Feb 28 '21 at 18:16
  • 1
    @AsifKamranMalick: It's possible that despite being different commit hash IDs, they might have the exact same timestamp. (Not very *likely*, but possible....) In that case the same sorting issue would come up. If they have different committer timestamps, though, a sort based on committer timestamp should be consistent, regardless of the branch name. – torek Mar 01 '21 at 03:21
  • jthill and torek. Honestly, I'm not able to recreate the issue as of now. Hence, no more in a state to comment on this. The order of every branch is constant now, no matter whichever of them I rename and then sort. Yours and jthill's explanations are perfectly valid and do make sense though. Just unlucky that the issue is not resurfacing. – Asif Kamran Malick Mar 01 '21 at 07:47
  • @jthill I ran your commands and they return different time stamps. – Asif Kamran Malick Mar 01 '21 at 07:51
  • 1
    Bring it in to the shop, it stops misbehaving. Been there. – jthill Mar 01 '21 at 08:27