Git pull keeps deleting everything I added

I have a git repository (let it be called "by default") with files A, B and C. (I actually update the modifications of others with svn.)

I cloned this repo to "defaultmods" and added the files D, E and F.

I noticed that someone updated A and C and added the G file, so I want these files to update and need a new file (G).

I go to the defaultmods repository and commit my changes. Then do git pull by default. It deletes my files (D, E and F) and leaves me with an exact working copy by default.

I want this to combine my stuff with updated materials giving me A, B, C, D, E, F and G (with updated A and C and a new G file).

Am I missing something strange? Does it work like this?

+3
source share
3 answers

You must be missing something, because it really is:

$ 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
+2
source

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. Do you want it to be used by default? At:

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

Decide at this point you want to combine defaultmods into a default value? At:

cd default
git merge ../defaultmods

Must be clean.

+2
source

git repo ( ) A, B, C. (I svn)

, R1: {A, B, C}

defaultmods D, E F...

, :

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

R2: {A, B, C, D, E, F} , .

- , :

git pull /path/to/R1 master

, R1.

R2: {A, B, C, D, E, F, G} C. R1 , . , , , , .

+1
source

Source: https://habr.com/ru/post/1712918/


All Articles