Skip to content

Instantly share code, notes, and snippets.

@sergeycherepanov
Created March 13, 2019 18:29
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save sergeycherepanov/b67d2c6b59fed549ab5541c03a5ca119 to your computer and use it in GitHub Desktop.
Save sergeycherepanov/b67d2c6b59fed549ab5541c03a5ca119 to your computer and use it in GitHub Desktop.
shallow update not allowed
Here's what I ended up doing - it worked perfectly. Note that I was moving from my old host (Bitbucket) to my new one (Gitlab). My comments are above the commands:
# First, shallow-clone the old repo to the depth we want to keep
git clone --depth=50 https://...@bitbucket.org/....git
# Go into the directory of the clone
cd clonedrepo
# Once in the clone's repo directory, remove the old origin
git remote remove origin
# Store the hash of the oldest commit (ie. in this case, the 50th) in a var
START_COMMIT=$(git rev-list master|tail -n 1)
# Checkout the oldest commit; detached HEAD
git checkout $START_COMMIT
# Create a new orphaned branch, which will be temporary
git checkout --orphan temp_branch
# Commit the initial commit for our new truncated history; it will be the state of the tree at the time of the oldest commit (the 50th)
git commit -m "Initial commit"
# Now that we have that initial commit, we're ready to replay all the other commits on top of it, in order, so rebase master onto it, except for the oldest commit whose parents don't exist in the shallow clone... it has been replaced by our 'initial commit'
git rebase --onto temp_branch $START_COMMIT master
# We're now ready to push this to the new remote repo... add the remote...
git remote add origin https://gitlab.com/....git
# ... and push. We don't need to push the temp branch, only master, the beginning of whose commit chain will be our 'initial commit'
git push -u origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment