FILE_TO_KEEP = pom.xml to keep only the pom.xml file from FOLDER_TO_KEEP Mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE || echo "Nothing to do"' -prune-empty -all 'git ls-files -s | grep $'\t'FILE_TO_KEEP$ | You don't want with the same name and commit.) git filter-branch -f -index-filter \ git filter-branch -subdirectory-filter subfolder1/subfolder2/FOLDER_TO_KEEP -allįor single file move only: go through what's left and removeĮverything except the desired file. git filter-branch -subdirectory-filter -all The result is the contents of directory 1 spewed out Go through your history and files, removing anything that is not inĭirectory 1. # -v (assuming myprojects is the repository you want to copy from)ĭelete the link to the original repository to avoid accidentally git clone -branch master -origin origin -progress \ Make a copy of repository A as the following steps make majorĬhanges to this copy which you should not push! git clone -branch -origin origin -progress \ It involves cloning the repository you want to move the file or folder from, moving that file or folder to the root, rewriting Git history, cloning the target repository and pulling the file or folder with history directly into this target repository. Having tried various approaches to move a file or folder from one Git repository to another, the only one which seems to work reliably is outlined below. ![]() Note that this involves merging the history into an existing repository, rather than simply creating a new standalone repository from part of another one ( as in an earlier question). Is there a better way to do this sort of thing in general? Or have I adopted the right approach? $ git merge p2 # -allow-unrelated-histories for git 2.9 īut that seems pretty convoluted. $ git commit -m "moved files to new subdirectory" > git mv $f deeply/buried/different/java/source/directory/B $ mkdir -p deeply/buried/different/java/source/directory/B $ git remote rm origin # so I don't accidentally overwrite the repo -) $ git filter-branch -subdirectory-filter deeply/buried/java/source/directory/A -all ![]() I did something like this: $ git clone project2 But in Git, each project is in its own repository, and today I was asked to move a subdirectory from project2 to project1. Obviously, it was pretty easy to move files from one to another with svn mv. ![]() Our Git repositories started out as parts of a single monster SVN repository where the individual projects each had their own tree like so: project1/branches
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |