views:

61

answers:

1

We are having havoc with our project at work, because our VCS is doing some awful merging when we move information across files.

The scenario is thus:

You have lots of files that, say, contain information about terms from a dictionary, so you have a file for each letter of the alphabet.

Users entering terms blindly follow the dictionary order, so they will put an entry like "kick the bucket" under B if that is where the dictionary happened to list it (or it might have been listed under both B, bucket and K, kick).

Later, other users move the terms to their correct files. Lots of work is being done on the dictionary terms all the time.

e.g. User A may have taken the B file and elaborated on the "kick the bucket" entry. User B took the B and K files, and moved the "kick the bucket" entry to the K file. Whichever order they end up getting committed in, the VCS will probably lose entries and not "figure out" that an entry has been moved.

(These entries are later automatically converted to an SQL database. But they are kept in a "human friendly" form for working on them, with lots of comments, examples etc. So it is not acceptable to say "make your users enter SQL directly".)

It is so bad that we have taken to almost manually merging these kinds of files now, because we can't trust our VCS. :(

So what is the solution? I would love to hear that there is a VCS that could cope with this. Or a better merge algorithm? Or otherwise, maybe someone can suggest a better workflow or file arrangement to try and avoid this problem?

+4  A: 

I would recommend:

  • using branching (that way, the order of commit does not matter: each developer records his/her own set of modifications in his/her own branch)
  • consolidate the branches on a main 'dico' branch where the conflicts can be resolved

(Git is especially good at this)


You can test it quickly:

C:\test\git>mkdir dico
C:\test\git>cd dico
C:\test\git\dico>git init
Initialized empty Git repository in C:/test/git/dico/.git/
C:\test\git\dico>echo words for B> B.txt
C:\test\git\dico>echo words for K> K.txt
C:\test\git\dico>git add -A & git commit -m "first letters"
[master (root-commit) e91d6fa] first letters
 2 files changed, 2 insertions(+), 0 deletions(-)
 create mode 100644 B.txt
 create mode 100644 K.txt

You have an empty dico in the master branch.
DevA comes along:

C:\test\git\dico>git checkout -b devA
Switched to a new branch 'devA'
C:\test\git\dico>echo Kick the Bucket: my def from devA>>B.txt
C:\test\git\dico>type B.txt
words for B
Kick the Bucket: my def from devA
C:\test\git\dico>git add -A & git commit -m "def from devA"
[devA 0f27595] def from devA
 1 files changed, 1 insertions(+), 0 deletions(-)

DevB comes along and get the work of devA:

C:\test\git\dico>git checkout master
Switched to branch 'master'
C:\test\git\dico>type B.txt
words for B
C:\test\git\dico>git checkout -b devB
Switched to a new branch 'devB'
C:\test\git\dico>git merge devA
Updating e91d6fa..0f27595
Fast forward
 B.txt |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

C:\test\git\dico>type B.txt
words for B
Kick the Bucket: my def from devA

Oh no! Wrong place for this definition!

C:\test\git\dico>echo words for B>B.txt
C:\test\git\dico>echo Kick the Bucket: my def from devA>>K.txt
C:\test\git\dico>git add -A & git commit -m "move def to K by devB"
[devB 473614d] move def to K by devB
 2 files changed, 1 insertions(+), 1 deletions(-)

Fix in devB branch. DevB goes on:

C:\test\git\dico>echo add to def by devB>>K.txt
C:\test\git\dico>git add -A & git commit -m "elaborate def by devB on K"
[devB f9ae17d] elaborate def by devB on K
 1 files changed, 1 insertions(+), 0 deletions(-)

Meaning, in the devA branch, devA also work on this definition:

C:\test\git\dico>git checkout devA
Switched to branch 'devA'
C:\test\git\dico>type B.txt
words for B
Kick the Bucket: my def from devA
C:\test\git\dico>type K.txt
words for K

C:\test\git\dico>echo elabore def from devA in B>>B.txt

C:\test\git\dico>type B.txt
words for B
Kick the Bucket: my def from devA
elabore def from devA in B

C:\test\git\dico>git add -A & git commit -m "devA go on on B.txt"
[devA 1da899a] devA go on on B.txt
 1 files changed, 1 insertions(+), 0 deletions(-)

If devB checks the devA's work, he will detect the conflict and resolve it appropriately:

C:\test\git\dico>git checkout devB
Switched to branch 'devB'

C:\test\git\dico>git merge devA
Auto-merging B.txt
CONFLICT (content): Merge conflict in B.txt
Automatic merge failed; fix conflicts and then commit the result.

C:\test\git\dico>git diff
diff --cc B.txt
index 1cc6ea9,a986721..0000000
--- a/B.txt
+++ b/B.txt
@@@ -1,1 -1,3 +1,6 @@@
  words for B
++<<<<<<< HEAD
++=======
+ Kick the Bucket: my def from devA
+ elabore def from devA in B
++>>>>>>> devA

He will remove the extra definition from B.txt and add it to K.txt (and then will go to devA and will tell him/her to STOP, merge his work, and go on in the right file!)

VonC