1

My question is quite simple but I can't find any solution.

I use electron-react-boilerplate for a project, so I cloned it using ---depth=1. Then, I was failing to push my changed to my own origin (a BitBucket repo), because I was developping on a shallow repo.

So I used git fetch --unshallow upstream (upstream being the boilerplate origin), however, as expected, it loaded all the commits from the boilerplate, which I don't want.

This makes the git tree dirty, is there a way to reverse the git fetch --unshallow command ? Reflog gives nothing. Moreover, why did I need the unshallow in the first place, since I was already pushing on my own repo ?

Eric Burel
  • 3,790
  • 2
  • 35
  • 56
  • 1
    Git has long-supported `git fetch --depth=...` as both *in*crease and *de*crease the depth of a clone: i.e., it now (but did not always) sets a fixed depth. It is, however, not clear to me just how that affects any commits *you* may have made (I see some ways it can be defined well and would hope Git uses those but this may be Git-version-dependent). There are still limitations on *pushing* from shallow clones, though: see http://stackoverflow.com/q/6900103/1256452 – torek Mar 27 '17 at 15:57

1 Answers1

1

meet the same situation, seems it's not easy directly.

shallow clone
https://stackoverflow.com/a/14930421/4896468

fetch branches
https://stackoverflow.com/a/37593674/4896468


I use this way, clone a new shallow repo,

fetch braches one by one, with
-depth NUM or
--single-brach --branch NAME
on demand



some cmds

clone

// one branch with 4 commit history

git clone --depth=4 --branch=mybranch  file:///run/test/linux linux_2

// one brach with all history (of this branch)

git fetch --single-branch --branch main file:///run/test/linux linux_3

fetch

cd linux_2

// one branch with 4 commit history

git remote set-branches origin 'branch1'
git fetch --depth 4 origin branch1
git checkout branch1

// one brach with all history (of this branch)

git remote set-branches origin 'branch2'
git fetch --single-branch origin branch2
git checkout branch2
yurenchen
  • 1,897
  • 19
  • 17