Reputation: 157
I use(just use not develop) some other people's git repos, but I don't want the whole history.
It seemed that 'git clone --depth 1' meets my requirements.
But
1) how can I trim the existing repos like I do a 'git clone --depth 1' ?
2) how can I update the repo without history, so the repo only remain the last commit?
Assume the reop's history is A-B-C, I execute 'git clone --depth 1', so I get a repo of C. Then the upstream update the repo, the history become A-B-C-D-E. Can I do some simple operation, so I get a repo of E? Delete the repo and execute 'git clone --depth 1' again?
I want this, because some repo's history is too big, the .git maybe 100M+, and my internet access is not so stable, so I want the last update only.
Solution
1) make a existing repo shallow:
git rev-parse HEAD > .git/shallow
git reflog expire --all --expire=now
git gc --aggressive --prune=now
2) update a shallow repo:
git fetch origin master --depth=1
git reset --hard origin/master
after upate several times, you can:
git reflog expire --all --expire=now
git gc --aggressive --prune=now
to remove old commits and files again.
Referece
How to update a git shallow clone?
Upvotes: 2
Views: 1539
Reputation: 3152
So you have a git repository locally that you have cloned. You want to get just the most recent version of the master branch.
git pull origin master --depth=1
This retrieves the latest 1 commit in the master branch and merges it into your local repository. If you have made any changes to your local version this may introduce merge conflicts that you have to deal with, but OP indicates that's not the case for them.
Upvotes: 1