-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

6
  • 3
    git rev-parse HEAD (after the commit) will output that info. Commented Jan 13, 2020 at 14:24
  • What happens if someone else commit a change in the same branch before i am executing the 'git rev-parse HEAD' Commented Jan 13, 2020 at 15:11
  • Someone else commiting on the remote branch won't affect your local version. Not until you pull. Commented Jan 13, 2020 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 Commented Jan 14, 2020 at 11:55
  • Can you update the question with a more detailed version of these new elements? Commented Jan 14, 2020 at 13:17

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.