Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git pull keeps deleting everything I've added

Tags:

git

merge

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?

like image 860
that0n3guy Avatar asked Sep 09 '26 08:09

that0n3guy


2 Answers

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
like image 56
Jim Puls Avatar answered Sep 12 '26 04:09

Jim Puls


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.

like image 23
Fake Code Monkey Rashid Avatar answered Sep 12 '26 03:09

Fake Code Monkey Rashid