Reputation: 165
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:
Thank you.
Upvotes: 2
Views: 499
Reputation: 488183
You can run git fetch
with --depth
to convert an existing (non-shallow) repository to a shallow repository of the given depth. You might also want to prune away all but one branch name (one local branch, and one corresponding remote-tracking branch), and change the fetch =
directive to match. If there are tags, you might want to prune some or all of those as well. Any references you keep will retain commits and their referenced objects.
That's fine for a regular repository, but as VonC noted in his answer to Git shallow submodules and ad22 mentioned in a comment:
... determining the exact depth needed for the revision pinned in the submodule is almost impossible to guess and is a moving target
If you control the servers, and have a new enough Git, you can enable fetch-by-hash-ID which will allow the submodules' hash IDs to be fetched directly, which will work around that as well. If not—if you don't control the servers or your Git is not that new—you will find submodules earning their "sob-modules" nickname yet again.
Upvotes: 1
Reputation: 9297
1st Answer :
Deleting the .git
folder 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_branch
Add all the files
git add -A
Commit the changes
git commit -am "commit message"
Delete the branch
git branch -D master
Rename the current branch to master
git branch -m master
Finally, force update your repository
git push -f origin master
Note :
this will not keep your old commit history around
2nd Answer :
You can clone your current git repository to a local repository in different folder before every pull or commit.
Syntax :
git clone -l -s -n [sourceFolder] [destinationFolder]
Example :
git clone -l -s -n . ../repo-backup
Note :
-l = When the repository to clone from is on a local machine
-s = When the repository to clone is on the local machine, instead of using hard links, automatically setup
.git/objects/info/alternates
to share the objects with the source repository.-n = No checkout of HEAD is performed after the clone is complete.
Upvotes: 0