I have been playing around to create a `subtree`.
I want to copy the `someFolder1` and `someFolder2` from `RepoFolderSrc` to `RepoFolderTarget`. I want to retain all the history for the folder `someFolder1` and `someFolder2` when it is copied over to the `featureBranch`.
A few of the solutions I have seen requires deleting the `origin` from `RepoFolderSrc`. I should not make any changes to the `RepoFolderSrc` and I should not create any additional branch or commits on the folder.
Is there a way by which I can copy over the folder by only playing around with the `RepoFoldertarget`. I do have push and pull permissions for all repositories.
If you're referring to the solution described in this blog post, as one of the ones you've seen but disliked how it worked because it made changes to the source repository, then I'm afraid to say that it is the canonical solution for getting done what you're describing. I also think you're misunderstanding when you say that the solution requires "deleting the `origin`" or "create additional branch or commits". Let me see if I can rephrase the solution more clearly.
Now, we are in the directory `backup/source` which is a completely new local copy of the `source` repo separate from any local copy you already have. Additionally, we want to protect https://github.com/user/source from being accidentally changed by our process here. We do that by deleting the `origin` remote, but only in this new local copy.
The result will contain that directory (and only that) as its project root.
Now we have a local repository that contains only the files and history that we want. We're halfway there! 🎉And remember, this is just a temporary place to store some work. It is completely separated from your normal local `source` repository and from https://github.com/user/source, so any changes we make here are not permanent. It's like making a temporary backup of a file so that you can revert back to the original if you screw something up.
This removes the link between our local `destination` repo and the temporary `source` repo. And when you're sure everything worked correctly, you can delete the modified local `source` repo whenever you feel like.
I hope that helps explain things a bit better! Let me know if you have any questions.
Really good answer. From my understanding, this will copy the most recent commit and the history for the specific subfolder. Is there a way to keep the source remote, and thus the hability to sync only that folder?
You can't keep the source remote and sync only that folder, no. But, you could remove the source folder from the original repository and add the new repository back to the original one as a submodule. I believe this would provide essentially the functionality you're looking for.
If I want to wrap your answer in a batch file, is there any way to revert the old repo to its original state before running this batch file?
I'm not sure I understand the question @agwatic. The whole point of my answer is for it to not change the original repo in any way, so I'm not sure what there would be to revert?
After making your tutorial I didn't manage to get back to the old state of the repo. How can I get back to the old state before extracting the directory from the repo?
As I said before, the process I described does not change the original repository. If your original repository was changed, can you tell me how exactly it was changed?
We had a similar issue, and used your solution but ended up losing part of history.
The folder we wanted to move to another repo was carried from different directory one year ago. In current repository we are able to see whole history but when I use filter-branch and extract the folder, the history before directory change was carried out is gone.
Do you have any ideas how we can keep whole history for this folder?