Re: [git-users] moving a directory from one repo to another with commit history
On Tue, 26 May 2015 23:43:43 +0530 Kalpa Welivitigoda callka...@gmail.com wrote: [...] Following is the output of $ git log --all --graph --decorate --oneline * 9c97cd4 (HEAD, master) Merge tag 'tags/Bdir12' |\ | * af56821 (tag: Bdir12) updating dir1-2 | * d0b8f8a adding dir1-2 * 2f4b0ae adding dir1 * 854521c adding dir1/dir1-3 * 6f54cfb adding dir1/dir1-1 * 2ff6f17 adding dir2 * 0710523 init commit [...] Extremely sorry for the confusion made. Let me explain, In repoB, $ git log --oneline dir1-2/ 43b1361 updating dir1-2 e68c343 adding dir1-2 In repoA, $ git log --oneline dir1/dir1-2/ 9c97cd4 Merge tag 'tags/Bdir12' My question is, shouldn't both of them return the same outcome (it is ok not to have the same hash, but the commits in repoB should be there in repoA, aren't they?) ? Ah, I think I understand now, thanks. The reason for this, apparently, is that tree objects referenced by commits af56821 and d0b8f8a do not actually hang off dir1 prefix as `git subtree split` did not know about it (and apparently there's no way to artifically make it think it's there). To spell it in other words, the first (and only) commit in repoB which has dir1-2 under dir1 is the merge commit 9c97cd4. The commits in the chain produced by `git subtree split` do not even know about dir1-2 (you can verify this by running `git ls-tree --name-only -r af56821`) as they refer to tree object that merely contain *the contents* of dir1-2. Well, I'm not sure what to do now... Do running $ git log --follow dir1/dir1-2 work for you -- descending into the history to the right side of the merge commit 9c97cd4? If yes, I'd stop here. If not, I'm afraid, some sort of `git filter-branch` mumbo-jumbo will be required on the chain produced by `git subtree split`: the idea is to rewrite each commit on that artifical branch with sort of the same commit but with all its files moved under the dir1/dir1-2 directory so that both names actually exist in the produced tree objects attached to the commits in the rewritten branch. Basically something along these lines (untested): $ cd repoA $ git branch Bdir12 $(git subtree split dir1-2) $ git filter-branch --tree-filter 'mkdir -p ./dir1/dir1-2 find . -mindepth 1 -path ./dir -prune -o -print | xargs mv -t ./dir/dir1-2' Bdir12 $ cd repoB $ git fetch ..\repoA Bdir12 ... and continue as before The script passed to `git filter-branch --tree-filter` is run once for each commit in the history of the branch being rewritten and will operate on the work tree of that commit checked out. The script creates the target directory hierarchy, then finds, recursively, all the files and directories in the work tree, except the newly created directory, and then moves them under that directory. The new commit produced by filter-branch will have all the files under dir1/dir1-2. -- You received this message because you are subscribed to the Google Groups Git for human beings group. To unsubscribe from this group and stop receiving emails from it, send an email to git-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [git-users] moving a directory from one repo to another with commit history
On Tue, 26 May 2015 22:24:25 +0530 Kalpa Welivitigoda callka...@gmail.com wrote: [...] Thanks for all the support rendered. I tried the above method and it places the directory from repoB to the correct place on repoA. But if I log the commits for dir1-2 in repoA (git log dir1/dir1-2), it shows only the merging of the tag, not the individual commits for that particular directory. But if I do a git log from root of repoA, it shows all the commits. Is it possible to have the commits for dir1-2 ? Given the merge commit, does $ git log that_merge_commit^2 show you the proper history line? yes, it is correctly displayed. Okay, see below. [...] Following is the output of $ git log --all --graph --decorate --oneline * 9c97cd4 (HEAD, master) Merge tag 'tags/Bdir12' |\ | * af56821 (tag: Bdir12) updating dir1-2 | * d0b8f8a adding dir1-2 * 2f4b0ae adding dir1 * 854521c adding dir1/dir1-3 * 6f54cfb adding dir1/dir1-1 * 2ff6f17 adding dir2 * 0710523 init commit Well, then I don't understand what's your problem with this, really... Does $ git log that_merge_commit^2 display commits af56821 updating dir1-2 d0b8f8a adding dir1-2 or not? I mean, that Git encantation which provided you with the nice ASCII-art display of your repository correctly rendered the merge commit 9c97cd4 as having two parents -- with the left (or baseline) commit being your repoB history and the right side being the history extracted using `git subtree split` from the repoB. So... Are these two commits really what you wanted to have or not? I'm asking because first you state that whatever you get is OK to you and then you cite the output of `git log ... --graph --all` but do not tell it looks OK to you. Hence I can't grasp if you're satisfied with the situation or need further assistance? If you do need it, then with what exactly? -- You received this message because you are subscribed to the Google Groups Git for human beings group. To unsubscribe from this group and stop receiving emails from it, send an email to git-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [git-users] moving a directory from one repo to another with commit history
On Tue, May 26, 2015 at 11:37 PM, Konstantin Khomoutov flatw...@users.sourceforge.net wrote: On Tue, 26 May 2015 22:24:25 +0530 Kalpa Welivitigoda callka...@gmail.com wrote: [...] Thanks for all the support rendered. I tried the above method and it places the directory from repoB to the correct place on repoA. But if I log the commits for dir1-2 in repoA (git log dir1/dir1-2), it shows only the merging of the tag, not the individual commits for that particular directory. But if I do a git log from root of repoA, it shows all the commits. Is it possible to have the commits for dir1-2 ? Given the merge commit, does $ git log that_merge_commit^2 show you the proper history line? yes, it is correctly displayed. Okay, see below. [...] Following is the output of $ git log --all --graph --decorate --oneline * 9c97cd4 (HEAD, master) Merge tag 'tags/Bdir12' |\ | * af56821 (tag: Bdir12) updating dir1-2 | * d0b8f8a adding dir1-2 * 2f4b0ae adding dir1 * 854521c adding dir1/dir1-3 * 6f54cfb adding dir1/dir1-1 * 2ff6f17 adding dir2 * 0710523 init commit Well, then I don't understand what's your problem with this, really... Does $ git log that_merge_commit^2 display commits af56821 updating dir1-2 d0b8f8a adding dir1-2 or not? I mean, that Git encantation which provided you with the nice ASCII-art display of your repository correctly rendered the merge commit 9c97cd4 as having two parents -- with the left (or baseline) commit being your repoB history and the right side being the history extracted using `git subtree split` from the repoB. So... Are these two commits really what you wanted to have or not? I'm asking because first you state that whatever you get is OK to you and then you cite the output of `git log ... --graph --all` but do not tell it looks OK to you. Hence I can't grasp if you're satisfied with the situation or need further assistance? If you do need it, then with what exactly? Extremely sorry for the confusion made. Let me explain, In repoB, $ git log --oneline dir1-2/ 43b1361 updating dir1-2 e68c343 adding dir1-2 In repoA, $ git log --oneline dir1/dir1-2/ 9c97cd4 Merge tag 'tags/Bdir12' My question is, shouldn't both of them return the same outcome (it is ok not to have the same hash, but the commits in repoB should be there in repoA, aren't they?) ? -- Best Regards, Kalpa Welivitigoda +94776509215 http://about.me/callkalpa -- You received this message because you are subscribed to the Google Groups Git for human beings group. To unsubscribe from this group and stop receiving emails from it, send an email to git-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [git-users] moving a directory from one repo to another with commit history
On Mon, May 25, 2015 at 5:30 PM, Konstantin Khomoutov flatw...@users.sourceforge.net wrote: On Sat, 23 May 2015 23:02:46 +0530 Kalpa Welivitigoda callka...@gmail.com wrote: [...] Use the `git subtree` command [*]. [...] To elaborate, a pseudocode (assuming a POSIX shell) is something like this: $ cd repoB $ git tag Bdir12 $(git subtree split dir1-2) $ cd ../repoA $ git fetch ../repoB Bdir12 $ git merge -s ours --no-commit Bdir12 $ git read-tree --prefix dir1/dir1-2 -u Bdir12 $ git commit --edit Thanks for all the support rendered. I tried the above method and it places the directory from repoB to the correct place on repoA. But if I log the commits for dir1-2 in repoA (git log dir1/dir1-2), it shows only the merging of the tag, not the individual commits for that particular directory. But if I do a git log from root of repoA, it shows all the commits. Is it possible to have the commits for dir1-2 ? Given the merge commit, does $ git log that_merge_commit^2 show you the proper history line? yes, it is correctly displayed. That ^2 thing selects the second parent of a commit, and in the case of a simple merge (two parents) this is the side which has been merged into -- that is, the tree extracted by `git subtree split`). On the same note, does $ git log that_tag_produced_by_git_subtree give you the history you're expecting to see? yes, it gives the same output as the above and that is the expected outcome. I mean, we have to tell if you have a problem extracting the history or the problem properly listing it (or some other problem). I'd also recommend running $ gitk --all or $ git log --all --graph --decorate --oneline to see a neatly layed of overview of the commit graph in your repo. In it, it should be easy to see if your merge commit actually has two parents with the second one having a history extracted from the source repo attached to it. I ran gitk --all on repoA and it seems there's only one parent. Following is the output of $ git log --all --graph --decorate --oneline * 9c97cd4 (HEAD, master) Merge tag 'tags/Bdir12' |\ | * af56821 (tag: Bdir12) updating dir1-2 | * d0b8f8a adding dir1-2 * 2f4b0ae adding dir1 * 854521c adding dir1/dir1-3 * 6f54cfb adding dir1/dir1-1 * 2ff6f17 adding dir2 * 0710523 init commit -- Best Regards, Kalpa Welivitigoda +94776509215 http://about.me/callkalpa -- You received this message because you are subscribed to the Google Groups Git for human beings group. To unsubscribe from this group and stop receiving emails from it, send an email to git-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [git-users] moving a directory from one repo to another with commit history
On Sat, 23 May 2015 23:02:46 +0530 Kalpa Welivitigoda callka...@gmail.com wrote: [...] Use the `git subtree` command [*]. [...] To elaborate, a pseudocode (assuming a POSIX shell) is something like this: $ cd repoB $ git tag Bdir12 $(git subtree split dir1-2) $ cd ../repoA $ git fetch ../repoB Bdir12 $ git merge -s ours --no-commit Bdir12 $ git read-tree --prefix dir1/dir1-2 -u Bdir12 $ git commit --edit Thanks for all the support rendered. I tried the above method and it places the directory from repoB to the correct place on repoA. But if I log the commits for dir1-2 in repoA (git log dir1/dir1-2), it shows only the merging of the tag, not the individual commits for that particular directory. But if I do a git log from root of repoA, it shows all the commits. Is it possible to have the commits for dir1-2 ? Given the merge commit, does $ git log that_merge_commit^2 show you the proper history line? That ^2 thing selects the second parent of a commit, and in the case of a simple merge (two parents) this is the side which has been merged into -- that is, the tree extracted by `git subtree split`). On the same note, does $ git log that_tag_produced_by_git_subtree give you the history you're expecting to see? I mean, we have to tell if you have a problem extracting the history or the problem properly listing it (or some other problem). I'd also recommend running $ gitk --all or $ git log --all --graph --decorate --oneline to see a neatly layed of overview of the commit graph in your repo. In it, it should be easy to see if your merge commit actually has two parents with the second one having a history extracted from the source repo attached to it. -- You received this message because you are subscribed to the Google Groups Git for human beings group. To unsubscribe from this group and stop receiving emails from it, send an email to git-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [git-users] moving a directory from one repo to another with commit history
On Fri, May 22, 2015 at 4:57 PM, Konstantin Khomoutov flatw...@users.sourceforge.net wrote: On Fri, 22 May 2015 14:19:08 +0300 Konstantin Khomoutov flatw...@users.sourceforge.net wrote: [...] Say we have two git repositories repoA and repoB with the following directory structure repoA --dir1 -- dir1-1 -- dir1-3 --dir2 repoB --dir1-2 I need to move the dir1-2 from repoB to repoA so that the directory structure of repoA will look like the following, repoA --dir1 -- dir1-1 -- dir1-2 -- dir1-3 --dir2 In doing so, I need to preserve the commit history for dir1-2 as well. [...] Use the `git subtree` command [*]. [...] To elaborate, a pseudocode (assuming a POSIX shell) is something like this: $ cd repoB $ git tag Bdir12 $(git subtree split dir1-2) $ cd ../repoA $ git fetch ../repoB Bdir12 $ git merge -s ours --no-commit Bdir12 $ git read-tree --prefix dir1/dir1-2 -u Bdir12 $ git commit --edit Thanks for all the support rendered. I tried the above method and it places the directory from repoB to the correct place on repoA. But if I log the commits for dir1-2 in repoA (git log dir1/dir1-2), it shows only the merging of the tag, not the individual commits for that particular directory. But if I do a git log from root of repoA, it shows all the commits. Is it possible to have the commits for dir1-2 ? -- Best Regards, Kalpa Welivitigoda +94776509215 http://about.me/callkalpa -- You received this message because you are subscribed to the Google Groups Git for human beings group. To unsubscribe from this group and stop receiving emails from it, send an email to git-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [git-users] moving a directory from one repo to another with commit history
On Fri, 22 May 2015 04:04:43 -0700 (PDT) Kalpa Welivitigoda callka...@gmail.com wrote: My question is basically moving a directory from one git repo to another with the commit history for that directory. Let me elaborate more. Say we have two git repositories repoA and repoB with the following directory structure repoA --dir1 -- dir1-1 -- dir1-3 --dir2 repoB --dir1-2 I need to move the dir1-2 from repoB to repoA so that the directory structure of repoA will look like the following, repoA --dir1 -- dir1-1 -- dir1-2 -- dir1-3 --dir2 In doing so, I need to preserve the commit history for dir1-2 as well. How can I achieve this? Are there any other alternative ways that I can achieve a similar outcome? Use the `git subtree` command [*]. First, use `git subtree split` to produce a synthetic chain of commits which only touched the directory you need the history of, then fetch that history into the destination repository and merge it there. For this, you can either use `git subtree add` or direct subtree merging [1]. Note that the commits in the chain `git subtree split` produces are synthetic (i.e. created by `git subtree split`), and their SHA-1 names do not match to those in the original repository's history. [*] This command should now be available as part of Git. If your Git install does not expose it directly, look for it in the contrib section of your Git install and run it there -- it's just a POSIX shell script. 1. https://www.kernel.org/pub/software/scm/git/docs/howto/using-merge-subtree.html -- You received this message because you are subscribed to the Google Groups Git for human beings group. To unsubscribe from this group and stop receiving emails from it, send an email to git-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [git-users] moving a directory from one repo to another with commit history
On 22 May 2015 at 13:04, Kalpa Welivitigoda callka...@gmail.com wrote: Hi, My question is basically moving a directory from one git repo to another with the commit history for that directory. Let me elaborate more. [...] How can I achieve this? Are there any other alternative ways that I can achieve a similar outcome? Take a look at `git filter-branch`. It's not easy to use, so I'd recommend only working on a copy of the original repo, and reading up on the command carefully before starting. /M -- Magnus Therning OpenPGP: 0xAB4DFBA4 email: mag...@therning.org jabber: mag...@therning.org twitter: magthe http://therning.org/magnus -- You received this message because you are subscribed to the Google Groups Git for human beings group. To unsubscribe from this group and stop receiving emails from it, send an email to git-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [git-users] moving a directory from one repo to another with commit history
On Fri, 22 May 2015 14:19:08 +0300 Konstantin Khomoutov flatw...@users.sourceforge.net wrote: [...] Say we have two git repositories repoA and repoB with the following directory structure repoA --dir1 -- dir1-1 -- dir1-3 --dir2 repoB --dir1-2 I need to move the dir1-2 from repoB to repoA so that the directory structure of repoA will look like the following, repoA --dir1 -- dir1-1 -- dir1-2 -- dir1-3 --dir2 In doing so, I need to preserve the commit history for dir1-2 as well. [...] Use the `git subtree` command [*]. [...] To elaborate, a pseudocode (assuming a POSIX shell) is something like this: $ cd repoB $ git tag Bdir12 $(git subtree split dir1-2) $ cd ../repoA $ git fetch ../repoB Bdir12 $ git merge -s ours --no-commit Bdir12 $ git read-tree --prefix dir1/dir1-2 -u Bdir12 $ git commit --edit -- You received this message because you are subscribed to the Google Groups Git for human beings group. To unsubscribe from this group and stop receiving emails from it, send an email to git-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.