views:

54

answers:

2

I have two files which are called

  1. version1
  2. version2

Version1 has my own changes, while version2 is based on version1 but it has other people's changes too.

I run the following command at my Git folder where Version1 is

git add version2

I now have two separate files in Git. I would like combine them now.

Which command should I run such that I have only Version2 and the history of Version1?

+1  A: 

Maybe I'm not understanding you properly, but it sounds like you should have added "version1", then open up "version2", and copy the whole file into "version1", overwriting what was there. Then delete "version2".

Chad Birch
+1  A: 

The best way to achieve what you are describing is to go in and change Version 1 with all of their changes and run the

git commit -a -m "incorporated others changes into Version1"

That way Git will track those changes and create two versions of Version1 one being the original and one with changes.

If you want more separation than that I would create a branch since branches are so easy to do in Git.

You could one master or raw branch where you keep the originals, then one where you keep the changes.

it would look something like this

$> mkdir src
$> cd src && git init .
$> touch Version1 && touch Version2
$> git add . && git commit -a -m "initial commit"
$> git checkout -b changes # this creates a branch called changes
# Make changes to the files
$> git commit -a -m "made some changes"
$> git checkout -b master  # back to your master branch.

Hope this helps.

ewakened
Thank you for your answer! Simple solutions are the best solutions :)
Masi
@ewakened: Your answer raised a new question. Let's assume we have two branches Version1 and Version2changes. Can we use the command rebase to make a new branch such that we get the changes in Version2changes? -- for instance, by $ git rebase Version1 Version2changes Version2.
Masi