2
git ls-remote --heads https://github.com/nanashili/AuroraEditor

9d84315555abdc1502ea2faf8c67401f4a27c226    refs/heads/179-toolbar-branch-selector-shows-when-no-git-repo
474bb8ab6629021769260145184983eb76b8c9d1    refs/heads/branch-delete-menu
afefeb5bbe89e8618e3f2ca6ff93718383f83145    refs/heads/development-main
474bb8ab6629021769260145184983eb76b8c9d1    refs/heads/file-creation
d24623b97fc863238b88179f03a24dca72aa44e9    refs/heads/git-init-fix
61fa98ba6a7b6f2fa518d3406016c304cbc83a9b    refs/heads/rename-branches

I have the following command which gives me the latest commit code of all branches of a specific repository.

I need to know the commit code of a specific repository.

That is, filter by the second column which would be the branch, just return its commit code.

For example, I want the commit code of the development-main branch, it should return "afefeb5bbe89e8618e3f2ca6ff93718383f83145".

Can you give me a hand?

torek
  • 448,244
  • 59
  • 642
  • 775
Paul
  • 3,644
  • 9
  • 47
  • 113
  • 1
    See [the `git ls-remote` documentation](https://git-scm.com/docs/git-ls-remote). Pay attention to the SYNOPSIS line. See that last thing in brackets? – torek Sep 10 '22 at 22:30
  • 1
    `git ls-remote --heads https://github.com/nanashili/AuroraEditor/ refs/heads/development-main | cut -f1` Do you say so? – Paul Sep 10 '22 at 22:33
  • That will do it, provided of course there is a `development-main`. Note that if you want to do this for multiple names, it's probably wisest to grab the `git ls-remote` output once, then peruse through it for each interesting item. – torek Sep 10 '22 at 22:35
  • I was having a look here: https://stackoverflow.com/questions/5188320/how-can-i-get-a-list-of-git-branches-ordered-by-most-recent-commit, how can I add the date when was the commit made? Is there something like --format = that I can use? – Paul Sep 10 '22 at 22:50
  • 1
    To get information on a commit, you must have the repository, or at least have the commit in question: `git ls-remote` won't get you what you need. Assuming you *do* have the commit, every commit has two date-and-time-stamps in its metadata: "author date" and "committer date". Use `git log` with `--format` or `--pretty=format` or `--pretty=tformat` to access them, using `%ad` and `%cd` and related formats. See the PRETTY FORMATS section of the `git log` documentation. – torek Sep 10 '22 at 22:53

0 Answers0