2

Is there any way to know which file, in a given Git commit, was created first and list said files in order they were created?

Note that their dates are equal to the commit date and we cannot use that date.

Imagine I have 3 files in 1 commit : a.js, b.js and c.js.
And they are not related to each other, so we can use their dependencies.
What should I do to achieve that goal?

I already tried to use git log, but the output is not in any specific order.
And I tried to use the file date in commit, but they were all the same, as mentioned before.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
mhmmdamiwn
  • 146
  • 9
  • 3
    Git does not know anything about dependencies between files - it just stores them. So I think my question to you is 'why do you need to know the order?' - that answer could lead to the solution to your problem. – JohnXF Mar 31 '23 at 10:12
  • @JohnXF I want the orders to use it in my project . do you know any possible way to get that? – mhmmdamiwn Mar 31 '23 at 10:14
  • 6
    'to use in my project' - why? If you - for some reason - need to know an 'order' for some files then you are best declaring that order explicitly in a file itself in some fashion. As you deal with files from repos or file systems dates of creation/modification/etc are all susceptible to change so relying on file time stamps will lead to problems. – JohnXF Mar 31 '23 at 10:17
  • Imagine I need that order for something. I cant rely on the commit date,now If you know a way I will gladly listen to you. – mhmmdamiwn Mar 31 '23 at 10:26
  • 3
    ... Could you just write what you are trying to achieve and why. It is incredibly stupid to ask how to solve one out of 10000 steps to solve your actual problem if there already exist a well-known, robust, and tested solution to said problem in the first place. – Kim Mar 31 '23 at 10:55
  • 1
    I'm afraid the commit date is the best you can get without manually storing some additional metadata. Why can't you rely on it? – Piotr Siupa Mar 31 '23 at 11:16
  • 2
    @mhmmdamiwn If you need that order for something then I suspect you are doing something wrong. So please explain why you need that order 'for something' and we can offer a more robust solution to your problem. There are other questions around getting the order of files added to Git - e.g. https://stackoverflow.com/questions/2390199/finding-the-date-time-a-file-was-first-added-to-a-git-repository - but it is not good practice. – JohnXF Mar 31 '23 at 11:16

1 Answers1

1

Git does not store the file-time, as I explained before (other explanation by torek).

But you have:

  • git utime, which changes files modification time to their last commit date.

  • Or git restore-mtime, packaged into Debian, Ubuntu, Linux Mint, Fedora, Gentoo Linux, and possibly other distributions.

  • git meta which stores all files' metadata into '.gitmeta'.

Any of those tools would bring you closer to seeing the files in order they were created.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250