1

I had created a shallow clone of a huge repository (for saving my time) using

git clone --depth=1 ...

Some days later, I thought I'd fetch the latest commits from the remote repository. I entered

git pull

but it started downloading a lot more info than I had in the first place (my initial shallow clone was ~150MB and here the pull was already downloading more than 100MB and showing 22%) so I pressed Ctrl-C and stopped it. After that, I tried (just randomly)

git pull --depth=1

and that threw up a lot of errors. And now I am left with a local repository where git status says:

# On branch master
# Your branch and 'origin/master' have diverged,
# and have 3 and 4 different commits each, respectively.
#

Is there any way to set things right, apart from creating a new shallow clone? I have no commits of my own so all is cool.

3 Answers 3

1

When you clone a repo with git, you get the repo's full history, from the first commit to the last, however, since you made a shallow clone, you only have the history depth that you specified.

If you know which commit you want to go back to, you could try git reset --hard _commit_ to revert your HEAD, the Index and the contents of your working directory to what they were in that specific commit (the first one, in this case).

If you don't remember which one it is, just use git log to check through the commits for the one you're looking for.

git log

commit c09ea7f2a7f01921fda4ee0b53934cba42fb9ee3
Author: That guy
Date:   The other day

This was your first commit

Remember that you only need the first few characters of the commit ID to reset so using:

git reset --hard c09ea7f2a7f019 

Should be enough to identify the commit as unique and reset your HEAD, Index and directory contents to how they were in that commit.

1

You can also do a

git pull --rebase --depth=1

This will try to rebase your local changes after the pull (although you haven't done anything but git thinks you have). And then git should tell you that there are conflicts because it will find the same changes in the files. Then you can just simply do a -

git rebase --skip

i.e. you are asking git not to apply your local changes. It should fix your problem.

1
  • Well, after doing this 'git status' on my local repository shows that everything is up-to-date, but checking from the remote repository over the web I can see that I don't have the latest commits. What next?
    – debamitro
    Feb 5, 2013 at 7:41
0
# delete local master and checkout remote
git branch -D master
git checkout master
# clean up any objects left by your interrupted pull
git prune
git gc

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .