I'm cloning many third-party projects' git repo under a "Third-party Software" subdirectory in my workspace, however I don't want to keep any history from them(the latest snapshot will do); also I'm sharing many same submodules in many project in separate repositories(like clean filter, pre-commit scripts...etc.) and don't want to keep history in any of them.
Here's two similar but slightly different questions:
- Is there any command to make these git repositories to drop all history snapshots?
- Is there any git config (or other method) to force git repositories/submodules to only keep the latest snapshot after every future pull/submodule update?
Thank you.
1st Answer :
Deleting the
.gitfolder may cause problems in your git repository. If you want to delete all your commit history but keep the code in its current state, it is very safe to do it as in the following:Checkout
git checkout --orphan latest_branchAdd all the files
git add -ACommit the changes
git commit -am "commit message"Delete the branch
git branch -D masterRename the current branch to master
git branch -m masterFinally, force update your repository
git push -f origin masterNote :
2nd Answer :
You can clone your current git repository to a local repository in different folder before every pull or commit.
Syntax :
Example :
Note :