Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Can a commit with the same hash be created/restored using the Bitbucket API?

Nagaraja November 6, 2023

Our objective is to find a backup solution for Bitbucket. Is it possible to create or restore the exact same commit hash?

1 answer

0 votes
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 7, 2023

Hello @Nagaraja and thank you for reaching out to Community!

As per what is described in How git sha1 is created the following information is used by git to generate a commit hash : 

  • The source tree of the commit (which unravels to all the subtrees and blobs)
  • The parent commit sha1
  • The author info (with timestamp)
  • The committer info (right, those are different!, also with timestamp)
  • The commit message

So won't be able to exactly recreate the same commit hash as several variables, such as the commit parents, the date of the commit, and the author will influence the generated hash of the new commit.

Could you elaborate more on why would you like to recreate a commit with the same SHA?

If you are looking to back up your repositories, we would suggest executing a mirror clone of it:

git clone --mirror <repository URL>

 as it will include all the objects/references that are stored in the remote end.

Let us know in case you have any questions.

Thank you, @Nagaraja !

Patrik S

Nagaraja November 8, 2023

Hello @Patrik S ,

Thank you for your reply. Based on the commit, it is known that those files should be assigned to that specific branch.
In order to restore the files, it is necessary to provide the commit hash.

Like Sabine Mayer likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events