简体   繁体   中英

Applying a raw Bitbucket commit file to your local git repo?

Is it possible to take the raw commit file shown from Bitbucket are a URL like https://bitbucket.org/myorg/myproject/commits/5fa326bef012df0a689c7ccaefed6ad61841e2ba/raw

and use that to merge all those changes into a local git repo?

Something squirely is happening with a Bitbucket repo I manage, and after a pull from the upstream branch, a bunch of commits disappeared from my local branch without even any trace of them in git log . However, Bitbucket is still showing the original commits and pull request, but they're not linked to the branch in any way.

Instead of manually copying down all my code changes, I'd like to just reapply the raw commit files.

What that endpoint provides is a Git-style patch for the commit. You can apply the patch using git am , but because patches lack committer information and timestamps, as well as any signatures, the object IDs will change, since Git will synthesize new committer information.

Patches also don't work for merges, which is likely going to be a problem for you. At the very least, applying one will not result in a merge commit.

If the server still has them listed in a branch, you can do git fetch origin (assuming origin is your remote), and then, assuming the branch is branch , inspect the remote tracking branch with git log origin/branch . If that contains the commits you want, you can then turn it into a local branch (eg, local ) with git branch local origin/branch .

If they're just available as a PR and not as a branch, you can try git fetch origin refs/pull-requests/<ID>/from:refs/heads/local , which will create a branch local from the given PR (substitute the appropriate ID). Then you'll have them, and don't have to recreate them.

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