gitgit-repogit-history

Can I shorten the history of a git repository


At first, I made a shallow-clone. After this, I found some old commits introducing some large files. For example, these old commits replaced a binary file again and again.

Now, I didn't want my local reposiotry containing these big changes. How can I shorten the history without recreating a new repository with git clone --depth=10?

# shallow clone
git clone --depth 100 ssh://git@10.7.222.111:/home/my_repository01.git
git log --oneline | wc -l  # the result is 100

# Now, how can I shorten the current history to 10? 
# Otherwise, I need to execute `git clone --depth=10` to recreate the repository.

Solution

  • You can use git fetch --depth=10 to update the current shallow depth.