I was cloned a repo, and its size increases day by day. So I want to remove old commits and only keep the latest commit just like I'm re-cloning it with --depth 1
. And I don't want to re-clone it, is there a way to convert the local repo to a shallow one and keep git pull
working?
Asked
Active
Viewed 1,133 times
2

Quanlong
- 24,028
- 16
- 69
- 79
-
2why don't you just clone locally however you want i.e. `cd /tmp/; git clone /my/fat/repo/.git --depth 1; ` - and then just move/rename/delete the directories as you see fit? – AD7six Apr 06 '16 at 10:02
-
you will also have to set up remote correctly – max630 Apr 07 '16 at 09:03
2 Answers
0
You can make a local copy of repository with using parameter "depth 1". Just use local folder as a source for cloning.
For example:
git clone --depth 1 file://__absolute path__/localrepo localrepo.shallow

Ntropy Nameless
- 846
- 1
- 6
- 7
-2
From what I understand in the question, you would like to preserve only the current state of the working directory and remove the history. If that is the case, checkout the branch you would like to keep. Then remove all the git information there is. I generally use these commands running it from the working directory:
find . -type f | grep -i "\.git" | xargs rm
cd ..
git init
cd
git add --all
git commit -m "commit_message"
This would create a local copy containing only the current commit.

Müller
- 973
- 6
- 19
- 38
-
-
You need to add the remote to this. git remote add
. And then you can do the git push – Müller Apr 06 '16 at 10:45