[tpm] [OT] Git repo combination
Abram Hindle
abram.hindle at softwareprocess.es
Thu Jan 17 13:11:15 PST 2013
Hi Antonio,
Here's a textual demo and I've attached a typescript. In this session I
merge proj1 into a subdir of proj2.
The subtree method is pretty well equivalent to this. I use cloning
because it is less hassle than pulling to a new branch.
abram
Script started on Thu 17 Jan 2013 01:59:15 PM MST
hindle1 at st-francis:/tmp/sun$ mkdir proj1
hindle1 at st-francis:/tmp/sun$ cd proj1/
hindle1 at st-francis:/tmp/sun/proj1$ git init
Initialized empty Git repository in /tmp/sun/proj1/.git/
hindle1 at st-francis:/tmp/sun/proj1$ man df > proj1.txt
hindle1 at st-francis:/tmp/sun/proj1$ man wc > proj1.1.txt
hindle1 at st-francis:/tmp/sun/proj1$ man man > proj1.2.txt
<standard input>:977: warning [p 8, 0.8i, div `3tbd1,0', 0.0i]: cannot
adjust line
<standard input>:986: warning [p 8, 0.8i, div `3tbd4,0', 0.0i]: cannot
adjust line
hindle1 at st-francis:/tmp/sun/proj1$ head proj1.2.txt
MAN(1) Manual pager utils
MAN(1)
NAME
man - an interface to the on-line reference manuals
SYNOPSIS
man [-C file] [-d] [-D] [--warnings[=warnings]] [-R
encoding] [-L
locale] [-m system[,...]] [-M path] [-S list] [-e extension]
[-i|-I]
hindle1 at st-francis:/tmp/sun/proj1$ ls
proj1.1.txt proj1.2.txt proj1.txt
hindle1 at st-francis:/tmp/sun/proj1$ git add *.txt
hindle1 at st-francis:/tmp/sun/proj1$ git commit -am 'add files'
[master (root-commit) 4360502] add files
3 files changed, 897 insertions(+)
create mode 100644 proj1.1.txt
create mode 100644 proj1.2.txt
create mode 100644 proj1.txt
hindle1 at st-francis:/tmp/sun/proj1$ head proj1.txt > proj1.txt
hindle1 at st-francis:/tmp/sun/proj1$ git commit -am 'truncate'
[master edf39f0] truncate
1 file changed, 117 deletions(-)
rewrite proj1.txt (100%)
hindle1 at st-francis:/tmp/sun/proj1$ sort proj1.2.txt > proj1.2.txt
hindle1 at st-francis:/tmp/sun/proj1$ git commit -am 'sort'
[master 51b7271] sort
1 file changed, 710 deletions(-)
rewrite proj1.2.txt (100%)
hindle1 at st-francis:/tmp/sun/proj1$ sort -n proj1.2.txt > proj1.2.txt
hindle1 at st-francis:/tmp/sun/proj1$ git commit -am 'sort'
# On branch master
nothing to commit (working directory clean)
hindle1 at st-francis:/tmp/sun/proj1$ cd ..
hindle1 at st-francis:/tmp/sun$ mkdir proj2
hindle1 at st-francis:/tmp/sun$ cd proj2/
hindle1 at st-francis:/tmp/sun/proj2$ git init
Initialized empty Git repository in /tmp/sun/proj2/.git/
hindle1 at st-francis:/tmp/sun/proj2$ mkdir t1
hindle1 at st-francis:/tmp/sun/proj2$ mkdir t2
hindle1 at st-francis:/tmp/sun/proj2$ mkdir t3
hindle1 at st-francis:/tmp/sun/proj2$ man ls > t1/t1.txt
hindle1 at st-francis:/tmp/sun/proj2$ man bash > t1/t2.txt
hindle1 at st-francis:/tmp/sun/proj2$ man bash | sort > t3/t3.txt
hindle1 at st-francis:/tmp/sun/proj2$ ls
t1 t2 t3
hindle1 at st-francis:/tmp/sun/proj2$ git add */*
hindle1 at st-francis:/tmp/sun/proj2$ git commit -am 'init'
[master (root-commit) 4d0fa8b] init
3 files changed, 11161 insertions(+)
create mode 100644 t1/t1.txt
create mode 100644 t1/t2.txt
create mode 100644 t3/t3.txt
hindle1 at st-francis:/tmp/sun/proj2$ sort t1/t1.txt > t1/t1.txt
hindle1 at st-francis:/tmp/sun/proj2$ git commit -am 'sorted'
[master d697636] sorted
1 file changed, 243 deletions(-)
rewrite t1/t1.txt (100%)
hindle1 at st-francis:/tmp/sun/proj2$ git log
commit d697636d78e861edd7917b8bebe182cd1c0febbb
Author: Abram Hindle <abram.hindle at ualberta.ca>
Date: Thu Jan 17 14:03:04 2013 -0700
sorted
commit 4d0fa8b0c1231b826e9b6424f080986bec6aaaeb
Author: Abram Hindle <abram.hindle at ualberta.ca>
Date: Thu Jan 17 14:02:47 2013 -0700
init
hindle1 at st-francis:/tmp/sun/proj2$ cd ..
hindle1 at st-francis:/tmp/sun$ cd proj2
hindle1 at st-francis:/tmp/sun/proj2$ git log
commit d697636d78e861edd7917b8bebe182cd1c0febbb
Author: Abram Hindle <abram.hindle at ualberta.ca>
Date: Thu Jan 17 14:03:04 2013 -0700
sorted
commit 4d0fa8b0c1231b826e9b6424f080986bec6aaaeb
Author: Abram Hindle <abram.hindle at ualberta.ca>
Date: Thu Jan 17 14:02:47 2013 -0700
init
hindle1 at st-francis:/tmp/sun/proj2$ cd ..
hindle1 at st-francis:/tmp/sun$ cd proj1
hindle1 at st-francis:/tmp/sun/proj1$ git log
commit 51b7271ec9f075b9d5ce4d2f7798b831ff2b88b4
Author: Abram Hindle <abram.hindle at ualberta.ca>
Date: Thu Jan 17 14:01:36 2013 -0700
sort
commit edf39f0c5d083383e2fa518f095265e44b734b7c
Author: Abram Hindle <abram.hindle at ualberta.ca>
Date: Thu Jan 17 14:01:19 2013 -0700
truncate
commit 4360502c32ca377f64f478e21421b5663372a8ed
Author: Abram Hindle <abram.hindle at ualberta.ca>
Date: Thu Jan 17 14:01:04 2013 -0700
add files
hindle1 at st-francis:/tmp/sun/proj1$ cd ..
hindle1 at st-francis:/tmp/sun$ ls
proj1 proj2 typescript
hindle1 at st-francis:/tmp/sun$ git clone proj1 proj1.prep
Cloning into 'proj1.prep'...
done.
hindle1 at st-francis:/tmp/sun$ cd proj1.prep/
hindle1 at st-francis:/tmp/sun/proj1.prep$ ls
proj1.1.txt proj1.2.txt proj1.txt
hindle1 at st-francis:/tmp/sun/proj1.prep$ mkdir proj1
hindle1 at st-francis:/tmp/sun/proj1.prep$ git mv *.txt proj1
hindle1 at st-francis:/tmp/sun/proj1.prep$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# renamed: proj1.1.txt -> proj1/proj1.1.txt
# renamed: proj1.2.txt -> proj1/proj1.2.txt
# renamed: proj1.txt -> proj1/proj1.txt
#
ir'dle1 at st-francis:/tmp/sun/proj1.prep$ git commit -am 'moved the root
to a subd
[master a97babd] moved the root to a subdir
3 files changed, 0 insertions(+), 0 deletions(-)
rename proj1.1.txt => proj1/proj1.1.txt (100%)
rename proj1.2.txt => proj1/proj1.2.txt (100%)
rename proj1.txt => proj1/proj1.txt (100%)
hindle1 at st-francis:/tmp/sun/proj1.prep$ git log
commit a97babdd7bccd51851c2c0d288de852dc884384a
Author: Abram Hindle <abram.hindle at ualberta.ca>
Date: Thu Jan 17 14:03:55 2013 -0700
moved the root to a subdir
commit 51b7271ec9f075b9d5ce4d2f7798b831ff2b88b4
Author: Abram Hindle <abram.hindle at ualberta.ca>
Date: Thu Jan 17 14:01:36 2013 -0700
sort
commit edf39f0c5d083383e2fa518f095265e44b734b7c
Author: Abram Hindle <abram.hindle at ualberta.ca>
Date: Thu Jan 17 14:01:19 2013 -0700
truncate
commit 4360502c32ca377f64f478e21421b5663372a8ed
Author: Abram Hindle <abram.hindle at ualberta.ca>
Date: Thu Jan 17 14:01:04 2013 -0700
hindle1 at st-francis:/tmp/sun/proj1.prep$ ls
proj1
hindle1 at st-francis:/tmp/sun/proj1.prep$ cd ..
hindle1 at st-francis:/tmp/sun$ ls
proj1 proj1.prep proj2 typescript
hindle1 at st-francis:/tmp/sun$ echo "now to merge into proj2"
now to merge into proj2
hindle1 at st-francis:/tmp/sun$ cd proj2/
hindle1 at st-francis:/tmp/sun/proj2$ ls
t1 t2 t3
hindle1 at st-francis:/tmp/sun/proj2$ git pull ../proj2/ master
>From ../proj2
* branch master -> FETCH_HEAD
Already up-to-date.
hindle1 at st-francis:/tmp/sun/proj2$ ls -l
total 12
drwxrwxr-x 2 hindle1 hindle1 4096 Jan 17 14:02 t1
drwxrwxr-x 2 hindle1 hindle1 4096 Jan 17 14:02 t2
drwxrwxr-x 2 hindle1 hindle1 4096 Jan 17 14:02 t3
hindle1 at st-francis:/tmp/sun/proj2$ #oops
hindle1 at st-francis:/tmp/sun/proj2$ git branch
* master
hindle1 at st-francis:/tmp/sun/proj2$ cd ../proj1.prep/
hindle1 at st-francis:/tmp/sun/proj1.prep$ git branch
* master
hindle1 at st-francis:/tmp/sun/proj1.prep$ cd ..
hindle1 at st-francis:/tmp/sun$ cd proj2/
hindle1 at st-francis:/tmp/sun/proj2$ git pull ../proj1.prep/ master
warning: no common commits
remote: Counting objects: 12, done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 12 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (12/12), done.
>From ../proj1.prep
* branch master -> FETCH_HEAD
Merge made by the 'recursive' strategy.
proj1/proj1.1.txt | 70
+++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 70 insertions(+)
create mode 100644 proj1/proj1.1.txt
create mode 100644 proj1/proj1.2.txt
create mode 100644 proj1/proj1.txt
hindle1 at st-francis:/tmp/sun/proj2$ ls -l
total 16
drwxrwxr-x 2 hindle1 hindle1 4096 Jan 17 14:05 proj1
drwxrwxr-x 2 hindle1 hindle1 4096 Jan 17 14:02 t1
drwxrwxr-x 2 hindle1 hindle1 4096 Jan 17 14:02 t2
drwxrwxr-x 2 hindle1 hindle1 4096 Jan 17 14:02 t3
hindle1 at st-francis:/tmp/sun/proj2$ ls -l proj1/
total 4
-rw-rw-r-- 1 hindle1 hindle1 2278 Jan 17 14:05 proj1.1.txt
-rw-rw-r-- 1 hindle1 hindle1 0 Jan 17 14:05 proj1.2.txt
-rw-rw-r-- 1 hindle1 hindle1 0 Jan 17 14:05 proj1.txt
hindle1 at st-francis:/tmp/sun/proj2$ git log
commit d9e3b6cc84a24bc572b3b6534b21b3f5f82eea1c
Merge: d697636 a97babd
Author: Abram Hindle <abram.hindle at ualberta.ca>
Date: Thu Jan 17 14:05:14 2013 -0700
Merge branch 'master' of ../proj1.prep
commit a97babdd7bccd51851c2c0d288de852dc884384a
Author: Abram Hindle <abram.hindle at ualberta.ca>
Date: Thu Jan 17 14:03:55 2013 -0700
moved the root to a subdir
commit d697636d78e861edd7917b8bebe182cd1c0febbb
Author: Abram Hindle <abram.hindle at ualberta.ca>
Date: Thu Jan 17 14:03:04 2013 -0700
sorted
commit 4d0fa8b0c1231b826e9b6424f080986bec6aaaeb
Author: Abram Hindle <abram.hindle at ualberta.ca>
hindle1 at st-francis:/tmp/sun/proj2$ git log --graph
* commit d9e3b6cc84a24bc572b3b6534b21b3f5f82eea1c
|\ Merge: d697636 a97babd
| | Author: Abram Hindle <abram.hindle at ualberta.ca>
| | Date: Thu Jan 17 14:05:14 2013 -0700
| |
| | Merge branch 'master' of ../proj1.prep
| |
| * commit a97babdd7bccd51851c2c0d288de852dc884384a
| | Author: Abram Hindle <abram.hindle at ualberta.ca>
| | Date: Thu Jan 17 14:03:55 2013 -0700
| |
| | moved the root to a subdir
| |
| * commit 51b7271ec9f075b9d5ce4d2f7798b831ff2b88b4
| | Author: Abram Hindle <abram.hindle at ualberta.ca>
| | Date: Thu Jan 17 14:01:36 2013 -0700
| |
| | sort
| |
| * commit edf39f0c5d083383e2fa518f095265e44b734b7c
| | Author: Abram Hindle <abram.hindle at ualberta.ca>
| | Date: Thu Jan 17 14:01:19 2013 -0700
| |
| | truncate
| |
| * commit 4360502c32ca377f64f478e21421b5663372a8ed
| Author: Abram Hindle <abram.hindle at ualberta.ca>
| Date: Thu Jan 17 14:01:04 2013 -0700
|
| add files
|
* commit d697636d78e861edd7917b8bebe182cd1c0febbb
| Author: Abram Hindle <abram.hindle at ualberta.ca>
| Date: Thu Jan 17 14:03:04 2013 -0700
|
| sorted
|
* commit 4d0fa8b0c1231b826e9b6424f080986bec6aaaeb
Author: Abram Hindle <abram.hindle at ualberta.ca>
Date: Thu Jan 17 14:02:47 2013 -0700
init
hindle1 at st-francis:/tmp/sun/proj2$ exit
Script done on Thu 17 Jan 2013 02:07:41 PM MST
On 13-01-17 01:52 PM, Antonio Sun wrote:
> Hi,
>
> Thanks a lot for your replies, everyone. Sorry for responding late,
> because I've got a lot of reading and trying to do. Now,
>
> First of all, a recap of what I want to do -- I have a local git repo
> to track my code, but I wasn't able to find a remote repo for it until
> recently. Thus, it is pure local. Now I just want to put my local
> code under a sub folder of a remote repo (and keep the histories).
> Afterward, there would be only one *combined *repo.
>
> Now, a recap of suggested solutions. Olaf and Matt suggested "git
> submodule" and "git subtree". Having read them though, I think the two
> method are more toward putting two separated git repo together, while
> having a way to maintain them separately. Same goal, different
> approaches.
>
> As Abram and Bobby, suggested a simple git merge would be good enough
> for my case. But the problem for me is that I not only have to know
> how to do it, but I had to figure out what git command should I use to
> do it. so,
>
> On Thu, Jan 17, 2013 at 12:42 PM, Abram Hindle
> <abram.hindle at softwareprocess.es
> <mailto:abram.hindle at softwareprocess.es>> wrote:
>
> One thing you can do is clone your local repo and then make the
> subdir in the clone. Then you tell the cloned git to move all
> files into that subdir. Then commit that.
>
>
> I was stuck at trying to move the git root into a sub folder, but in
> the end, I made it.
>
>
>
> Now your clone repo needs the commits of the remote repo.So pull
> the branch from remote into the cloned repo. Now you have merged
> the commits.
>
>
> This is the step I get stuck again. I wasn't able to figure out what
> git command I should use to pull the branch from remote into the
> cloned repo, or as Bobby's method, to merge to Repo-B. (I was trying
> to do "git remote add origin", but got the "fatal: remote origin
> already exists" error for my pure local git clone; and I don't know
> how to merge to remote Repo-B at this point).
>
> Please help.
>
> Thanks.
>
>
>
> Now you can push back to the remote.
>
>
> Now your remote repo has your new local repo inside of it. You
> probably should just use this new local merged repo instead of the
> old one.
> --
> Abram Hindle
>
> Sent from my Android powered rock tumbler
>
> Antonio Sun <antoniosun at lavabit.com
> <mailto:antoniosun at lavabit.com>> wrote:
>
>
>
>
> On Thu, Jan 17, 2013 at 11:22 AM, Olaf Alders
> <olaf.alders at gmail.com <mailto:olaf.alders at gmail.com>> wrote:
>
>
> > An off-topic question on Git -- how to put my locally
> managed Git repo under a sub-folder of another remote Git repo?
> >
> > My locally managed Git repo was created totally locally,
> without any remote repo. Now I hope everything, including the
> histories, can show up under a sub-folder of another remote
> Git repo.
>
>
> Hi Antonio,
>
> I think you want "git submodule".
>
> http://git-scm.com/book/en/Git-Tools-Submodules
>
>
> Thanks Olaf,
>
> That's not quite what I was looking for. For git submodule, "you
> want to be able to treat the two projects as *separate *yet still
> be able to use one from within the other. . . Submodules allow
> you to keep a Git repository as a subdirectory of another Git
> repository. This lets you clone another repository into your
> project and keep your commits separate."
>
> I wasn't able to find a remote repo for my local repo until
> recently, now I just want to give my local repo a remote repo, but
> should be under a sub folder. Afterward, there would be only one
> *combined *repo. Would that be possible?
>
> Thanks
>
>
>
>
> _______________________________________________
> toronto-pm mailing list
> toronto-pm at pm.org
> http://mail.pm.org/mailman/listinfo/toronto-pm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: typescript
Type: application/octet-stream
Size: 16835 bytes
Desc: not available
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20130117/8aff3e71/attachment-0001.obj>
More information about the toronto-pm
mailing list