Reputation: 5311
I am releasing a private repository to be accessible by public. I need to release a particular version of the repo (the one my report is based on), and then remove all the commits history from this released version.
A simple solution is cloning the version first, and then removing all the git footprints from the cloned project and push it somewhere as a fresh project. But I wonder if there is any other way of doing this which is more professional.
Upvotes: 6
Views: 5063
Reputation: 2883
You can add the public repo as a remote, have a dedicated branch for that repo, merge the local master to the dedicated branch when ready to publish and push dedicated branch to public repo.
git remote add public <url-to-public-repo>
git fetch public
git checkout -b public-master public/master
git merge --squash master
git add .
git commit -m "Publish changes to public repo"
git push public public-master:master
This will merge all changes in local master branch into local public-master branch as one commit and push that single merge commit to the public repo.
The merge --squash
command results in
Squash commit -- not updating HEAD
Automatic merge went well; stopped before committing as requested
which is expected and you can tailor the commit before publishing it.
Then, each time you need to publish your new changes in master
git checkout -b public-master public/master
git pull
git merge --squash master
git add .
git commit -m "Publish more changes"
git push public public-master:master
Upvotes: 0
Reputation: 1031
You can use git-rebase:
Go to the revision that you want it to be the first.
git checkout yourRevision
Look the SHA1 of the very first commit (for example: aaaaaa)
git checkout -b newMaster // temporal branch
git rebase -i aaaaaa // Your first SHA1
Your editor will open. Replace each "pick" option to "squash" option but leave the first one (aaaaaa) with "pick". Save it and exit.
A new complete history of only one commit will be generated.
Now you have to add the rest of commits.
git checkout yourRealMasterBranch
git rebase --onto newMaster yourRevision yourRealMasterBranch
This regenerates the rest of the history.
Now, you can clone your repository and the new one only will have this new history that you have created. And you can still have in your original one all the history.
Upvotes: -1
Reputation: 4184
I would just make a copy of the entire repo at the desired revision, then do the following on the copy:
.git
directorygit init
I don't see any problem with this.
Upvotes: 14
Reputation: 4833
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
Hope this helps. also this will not keep your old commit history around :)
Upvotes: 3