(Note: the repository will be cloned using hard-links, but that is not a problem since the hard-linked files will not be modified in themselves – new ones will be created.) To clone your local repository: git clone /XYZ /ABC You want to clone your repository and then use git filter-branch to mark everything but the subdirectory you want in your new repo to be garbage-collected. See here: Detach (move) subdirectory into separate Git repository Update: This process is so common, that the git team made it much simpler with a new tool, git subtree. GIT ADD REMOTE REPOSITORY TO A SUBDIRECTORY HOW TOHow to remove unreferenced blobs from my git repo.Remove a directory permanently from git.That said, I’d recommend not performing these steps unless you know that you need to – just in case you did prune the wrong subdirectory, y’know? The backup files shouldn’t get cloned when you push the repo, they’ll just be in your local copy. Git reflog expire -all -expire-unreachable=0 So if you really want to empty the trash to reduce the clone size of a repo immediately you have to do all of this really weird stuff: rm -rf. It will eventually delete orphaned files over the days and months, but it leaves them there for a while in case you realize that you accidentally deleted something you didn’t want to. The aforementioned delete history command still leaves behind a bunch of backup files – because Git is all too kind in helping you to not ruin your repo by accident. GIT ADD REMOTE REPOSITORY TO A SUBDIRECTORY PASSWORDBut wait – there’s more! – if you’re really concerned about getting rid of a password or something like that you’ll need to prune the backup (see below). So if you want to delete history from the “origin” – meaning to delete it from GitHub, Bitbucket, etc – you’ll need to delete the repo and re-push a pruned copy of the repo. If you try, you’ll get an error and you’ll have to git pull before you can git push – and then you’re back to having everything in your history. However, you can’t “push” deletes to GitHub and the like. you committed a password), you need to do this: git filter-branch -prune-empty -tree-filter 'rm -rf ' HEADĪfter that, you can check that your file or folder no longer shows up in the Git history at all git log - # should show nothing If you want to actually remove the historical references (i.e. Clearing your historyīy default removing files from Git doesn’t actually remove them, it just commits that they aren’t there anymore. usr/share/doc/git/contrib/subtree/git-subtree.sh \ If that still doesn’t work, try sudo chmod x /usr/share/doc/git/contrib/subtree/git-subtree.sh If that doesn’t work (you have a very old version of Ubuntu), try sudo add-apt-repository ppa:git-core/ppa GIT ADD REMOTE REPOSITORY TO A SUBDIRECTORY INSTALLTo get the latest version of Git using Homebrew: brew install git Lastly, I’ll want to remove the folder from the bigger repo git rm -rf btoa gitignore and LICENSE, you will need to pull first: git pull origin master Note: If you created a repo with a README.md. Next, I create a new repo on GitHub or Bitbucket, or whatever and add it as the origin git remote add origin :node-browser-compat/btoa.git I now have a new branch, btoa-only, that only has commits for btoa and I want to create a new repository. I want to split out a single folder, btoa, into a separate Git repository cd ~/node-browser-compat/ Here’s a project I have for implementing JavaScript browser modules in node: tree ~/node-browser-compat These are the same steps as above, but following my exact steps for my repository instead of using. See the Appendix below if you’re actually concerned about having committed a password or you need to decreasing the file size of your. Note: This leaves all the historical references in the repository. Link the new repo to GitHub or wherever git remote add origin For instance, the folder named path1\path2\subproject MUST be passed as path1/path2/subproject GIT ADD REMOTE REPOSITORY TO A SUBDIRECTORY WINDOWSNote for Windows users: When your folder depth is > 1, must have *nix style folder separator (/). For instance, the folder named subproject MUST be passed as subproject, NOT. Note: must NOT contain leading or trailing characters. Also, there’s a real-world example in the walkthrough below. See the appendix for how to install the latest Git. It turns out that this is such a common and useful practice that the overlords of Git made it really easy, but you have to have a newer version of Git (>= 1.7.).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |