简体   繁体   中英

Git cherry-pick and sha-1 value

In https://git-scm.com/book/en/v2/Distributed-Git-Maintaining-a-Project is example that shows how to cherry pick on a branch. In this example the sha-1 value of commit is used in full length?

$ git cherry-pick e43a6fd3e94888d76779ad79fb568ed180e5fcdf

Doesn't the cherry-pick allow short sha-1 values like e43a6, so that the following is valid?

$ git cherry-pick e43a6

Yes, but the provided SHA snippet has to identify unique refspec. Take a look here: How much of a git sha is *generally* considered necessary to uniquely identify a change in a given codebase?

Yes, you can use the short value anywhere you can use the long hash. Not sure about the intent behind the doc using the full hash, but git cherry-pick e43a6 works too.

Guideline on short hash:

The full SHA-1 object name (40-byte hexadecimal string), or a leading substring that is unique within the repository. Eg dae86e1950b1277e545cee180551750029cfe735 and dae86e both name the same commit object if there is no other object in your repository whose object name starts with dae86e.

https://git-scm.com/docs/gitrevisions

Bonus:

Default short hash is 7 character in length:

git rev-parse --short e43a6fd3e94888d76779ad79fb568ed180e5fcdf
e43a6fd

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM