Merge 2 versions of a file

Hey guys I was just wondering if there was some kind of a library or something that would take 2 versions of a file and would make a third file with attributes from both files, and if they conflict somewhere, it would take the stuff from the later modified one...

For example, imagine I have a file config.json. It's contents are:

1
2
3
{
  "config" : "1"
}


And I give that file to my friend. He modifies the file a bit and now it looks like this:

1
2
3
4
{
  "config" : "1",
  "edited" : "1"
}


And at the same time I also modify my file and now on my computer it looks like this:

1
2
3
{
  "config" : "0"
}


Later my friend gives his modified file back to me, and I want to combine our files to get the final version with our both editions. So the result should be this:

1
2
3
4
{
  "config" : "0",
  "edited" : "1"
}



While I was writing this I realized I would probably need the original version without any edits too...
PonasM wrote:
Hey guys I was just wondering if there was some kind of a library or something that would take 2 versions of a file and would make a third file with attributes from both files, and if they conflict somewhere, it would take the stuff from the later modified one...

you basically just described git

https://git-scm.com/
https://github.com/
https://en.wikipedia.org/wiki/Git
Last edited on
merging complex code gets ugly fast though.

say I wrote this last week:

int main()
{
int x = 10;
}

and you came along and removed the unused variable because it gave a compiler warning.
meanwhile I edited the code to be

int main()
{
int x = 10;
cout << x << endl;
}

the merged code is this:

int main()
{
cout << x << endl;
}

I don't remember if version control tools handle this well or not. Most *prevent* this from happening by keeping the code from being edited by more than 1 person at one time via a checkout system (like a library book, only one person can have it at one time). I don't think I have ever worked on code with multiple editors allowed. If something gets messed up, last time I used one of these, you had to reassemble the code by hand by grabbing the last good version, the new version, running windiff/beyond compare/etc and fixing each difference on a case by case approach with both developers working together. (this is the case of one editor at a time, but the latest copy broke something that used to work AND added new important good stuff)
Last edited on
Any revision control system like Git or Subversion does this.
The oldest (AFAIK) programs to handle this are patch and diff.
Conflicts must be manually handled.
Topic archived. No new replies allowed.