Can't combine Version2 with Version1 in Git

I have two files called

  • version1
  • version2

Version 1 has its own changes, and version2 has version 1, but it has other changes as well.

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

git add version2

      

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

What command should I run to only have version2 and history of version1?

+1


a source to share


2 answers


The best way to achieve what you describe is to go in and change version 1 with all their changes and run

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

      

Thus, Git will track those changes and create two versions of version 1, which is the original and the other with the changes.

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



You can create master or raw branch where you save the originals and then save your changes.

it will 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 it helps.

+1


a source


I may not be understanding you correctly, but it looks like you should add "version1", then open "version2" and copy the entire file to "version1", overwriting what was there. Then remove "version2".



+1


a source







All Articles