What I'm trying to do: test pull requests from github. I want to locally merge a pull request into master and run some tests on the result. Since the repository is huge, I do a shallow clone.
To be able to do the merge, I fetch more and more commits (git fetch
with increasing --depth
) until I have the merge-commit
between master the pull request.
However, it doesn't work every time. It looks like I do not only need the merge-base, but also every commit in the master..merge
_base range. I'm not sure however how to do that.
So, the question is: how do I fetch enough history to do the merge?
3-way merges use a dedicated commit to tie together the two histories. The nomenclature comes from the fact that Git uses three commits to generate the merge commit: the two branch tips and their common ancestor.
If the source repository is shallow, fetch as much as possible so that the current repository has the same history as the source repository. --update-shallow. By default when fetching from a shallow repository, git fetch refuses refs that require updating . git/shallow. This option updates .
A shallow clone is a repository created by limiting the depth of the history that is cloned from an original repository. The depth of the cloned repository, which is selected when the cloning operation is performed, is defined as the number of total commits that the linear history of the repository will contain.
"Clone depth" is a feature of git to reduce server load: Instead of cloning the complete repository (as usually done with git), using clone depth just clones the last clone-depth-number revisions of your repository. In literature this is also called "shallow clone"
If you have the history from when feature
branched from master
but don't want the full history of master then you can estimate a branching date and use;
git fetch --shallow-since=<date> origin master
It's hard to use any other form of git fetch
to do what you want (query the remote for the merge-base) because git fetch
fetches refs. There might not be a ref that you're looking for.
You can automate the digging using the following script.
while [ -z $( git merge-base master feature ) ]; do git fetch -q --deepen=1 origin master feature; done
What you need (I think), in a catch-22 way, is 'git describe --all --first-parent' to tell you the depth of the given commit from the appropriate branch. However I'm not sure how to get that from Github before you do your shallow fetch ;-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With