-1

I am using the below command to push the git changes using powershell.

 git commit -a -m "message"
 git push -q

While performing the git commit i want to return the corresponding commit id so that i can use that git id later for getting the corresponding changes.Is it possible

mystack
  • 4,910
  • 10
  • 44
  • 75
  • 3
    `git rev-parse HEAD` (after the commit) will output that info. – Romain Valeri Jan 13 '20 at 14:24
  • What happens if someone else commit a change in the same branch before i am executing the 'git rev-parse HEAD' – mystack Jan 13 '20 at 15:11
  • Someone else commiting on the remote branch won't affect your local version. Not until you pull. – Romain Valeri Jan 13 '20 at 15:18
  • But when i try to return the comitid in a function it is getting as an array with the below values , On branch master, Your branch is up to date with 'origin/master'., , nothing to commit, working tree clean, On branch master, Your branch is up to date with 'origin/master'., , nothing to commit, working tree clean,7de234567f68fa8a3b40a95abc4d6d82a75d93 – mystack Jan 14 '20 at 11:55
  • Can you update the question with a more detailed version of these new elements? – Romain Valeri Jan 14 '20 at 13:17
  • i have added a new question https://stackoverflow.com/questions/59735738/return-git-commit-id-in-powershell – mystack Jan 14 '20 at 14:26

1 Answers1

1

You can use :

git show --no-patch --no-notes --pretty='%H' @

… to get the full 40-digit hash pointed by HEAD, which is supposed to be the latest commit in date if you committed on the current branch.

Obsidian
  • 3,719
  • 8
  • 17
  • 30
  • What happens if someone else commit a change in the same branch before executing this command. That's why i asked is there any way to get it as a response to git commit – mystack Jan 13 '20 at 15:15
  • Nothing will happen on your local repository (if you call it before you push) NOR on the remote one : objects are immutable, so your commit ID will always remain the same. If somebody push something on the repository before you do, you'll then be warned about discrepancies and asked to perform a merge operation first, which will result in another distinct commit. But once all repositories are synchronised, hashes should be the same everywhere. – Obsidian Jan 13 '20 at 16:09