Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fetch enough commits to do a merge in a shallow clone

Tags:

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?

like image 454
madjar Avatar asked Nov 21 '14 11:11

madjar


People also ask

Which commits are involved in 3 way 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.

What is shallow fetch?

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 .

What is shallow clone?

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.

What is git clone depth?

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


2 Answers

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 
like image 62
Adam Avatar answered Sep 28 '22 03:09

Adam


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 ;-)

like image 31
Philip Oakley Avatar answered Sep 28 '22 03:09

Philip Oakley