views:

210

answers:

3

I've just started using git, been used to bzr in the past. Here is my problem:

I have a git repo (let's call it "default") with files A, B, and C. (I actually update others' modifications with svn.)

I clone that repo to "defaultmods" and add files D, E, and F.

I notice that someone updated A and C and added file G so I want those files updated and want the new file (G).

I go to my "defaultmods" repo and commit my changes. Then do a git pull from default. It deletes my files (D,E, and F) and leaves me with an exact working copy of default.

What I want is it to merge my stuff with the updated stuff giving me A, B, C, D, E, F, and G (with the updated A and C and new G file).

Am I missing something weird? Does it not work this way?

+1  A: 

I have a git repo (lets call it default)with files A, B, C. (I actually update others modifications with svn)

So, we have R1: { A, B, C }

I clone that repo to defaultmods and add files D, E, and F...

So, you do a:

git add .    
git commit -a -m "Added D, E, and F"

Now we have R2: { A, B, C, D, E, F } So, now everything is committed and happy.

Now, you should be doing something to the effect of:

git pull /path/to/R1 master

to pull the changes R1 has made.

Now, R2: { A, B, C, D, E, F, G } with changes to A and C. R1 is going to be behind though. Which is fine, but can cause potential merge conflicts if you guys are collaborating.

Justin Van Horne
+2  A: 

There must be something you're leaving out, because it does, in fact, worth this way:

$ mkdir default
$ cd default/
$ git init
Initialized empty Git repository in /Users/jim/Desktop/default/.git/
$ echo "A" > A; echo "B" > B; echo "C" > C
$ git add . && git commit -m "Initial commit"
[master (root-commit) 318f655] Initial commit
 3 files changed, 3 insertions(+), 0 deletions(-)
 create mode 100644 A
 create mode 100644 B
 create mode 100644 C
$ cd ..
$ git clone ./default ./defaultmods
Initialized empty Git repository in /Users/jim/Desktop/defaultmods/.git/
$ cd defaultmods/
$ echo "D" > D; echo "E" > E; echo "F" > F
$ cd ../default
$ echo "A, updated" > A; echo "C, updated" > C; echo "G" > G
$ git add . && git commit -m "Upstream update"
[master 4485f72] Upstream update
 3 files changed, 3 insertions(+), 2 deletions(-)
 create mode 100644 G
$ cd ../defaultmods/
$ git add . && git commit -m "Mods commit"
[master a393e70] Mods commit
 3 files changed, 3 insertions(+), 0 deletions(-)
 create mode 100644 D
 create mode 100644 E
 create mode 100644 F
$ git pull
remote: Counting objects: 8, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 5 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (5/5), done.
From /Users/jim/Desktop/./default
   318f655..4485f72  master     -> origin/master
Merge made by recursive.
 A |    2 +-
 C |    2 +-
 G |    1 +
 3 files changed, 3 insertions(+), 2 deletions(-)
 create mode 100644 G
$ cat *
A, updated
B
C, updated
D
E
F
G
Jim Puls
+1  A: 

You want: A, C and G. Do:

cd default
git pull [wherever A, C and G are located]
[resolve merges]

You now have A, C and G. Want it in defaultmods? Do:

cd defaultmods
git rebase ../default
[resolve merges]

Decide at this point you want to merge defaultmods into default? Do:

cd default
git merge ../defaultmods

Should be a clean one.

Fake Code Monkey Rashid