-4
  • working with git for the first time and encountered a problem with merging. the work flow was something as follows:

  • created repository on gitlab and each member linked locally

  • added two text files to master branch - recipe_book.txt and ingredients.txt
  • edited the two file and they were added, committed and pushed
  • created two branches from master - vegetarian and pizza-pasta
  • in pizza-pasta branch both files were re-written (not just slightly modified), added committed and pushed.
  • in vegetarian branch both files were re-written (not just slightly modified), added committed and pushed.
  • on master - master and pizza-pasta were merged this resulted in a fast-forward merge (as suggested below) -reverted to commit pre-merge -tried no fast-forwarding merge however only parts of the content of files in pizza-pasta were added to the content of the files in master.

the aim of this task is to two files in three different branches (files must retain same name however content must be completely different) in the end all the branches must be merged so that the files in the master branch contain the content that was originally in each of the three branches.

summary of commands used (editing of files was done manually and locally by each participant):

    git add ingredients.txt
    git commit -m "adding blank file ingredients.txt"
    git add recipe_book.txt
    git commit -m "adding blank file recipe_book.txt"
    git push -u origin master
    git add ingredients.txt
    git commit -m "updating file ingredients.txt with content"
    git add recipe_book.txt
    git commit -m "updating file recipe_book.txt with content"
    git push -u origin master
    git branch vegetarian
    git push origin vegetarian
    git branch pizza-pasta
    git push origin pizza-pasta
    git checkout vegetarian
    git add ingredients.txt
    git commit -m "updating file ingredients.txt with completely new content"
    git add recipe_book.txt
    git commit -m "updating file recipe_book.txt with completely new content"
    git push -u origin vegetarian
    git checkout pizza-pasta
    git add ingredients.txt
    git commit -m "updating file ingredients.txt with completely new content"
    git add recipe_book.txt
    git commit -m "updating file recipe_book.txt with completely new content"
    git push -u origin pizza-pasta
    git checkout master
    git merge master pizza-pasta \\ here i made the fast-forward merge mistake
    git reset --hard fe6fff
    git reset --soft HEAD@{1}
    git commit -m "reverting to pre-merge"
    git push -u origin master
    git merge --no-ff master pizza-pasta \\ here i made the merge with no fast-forward 
John
  • 71
  • 1
  • 10
  • Welcome to Stack Overflow. Retrace your steps, you didn't do what you think you did, the downvotes (none mine, though it was close-ish call) are because it's not worth anybody's time to handhold you through rechecking such simple steps. See [How to ask a good question](https://stackoverflow.com/help/how-to-ask), in particular the "help others reproduce the problem" section. – jthill Nov 14 '17 at 22:27

1 Answers1

0

If the vegetarian branch edits the recipe_book.txt by removing/fully changing all lines and then adding back vegetarian lines, then merging back to master will look like an "overwrite" (but really was just a fast-forward merge).

$ git init
Initialized empty Git repository in /code/test-git/.git/
$ touch recipe_book.txt
$ echo steak > recipe_book.txt
$ cat recipe_book.txt
steak
$ git add recipe_book.txt
$ git commit -m "steak"
[master (root-commit) 25b1f57] steak
 1 file changed, 1 insertion(+)
 create mode 100644 recipe_book.txt
$ git checkout -b veg
Switched to a new branch 'veg'
$ echo tofu > recipe_book.txt
$ cat recipe_book.txt
tofu
$ git commit -am "tofu"
[veg e765cb4] tofu
 1 file changed, 1 insertion(+), 1 deletion(-)
$ git checkout master
Switched to branch 'master'
$ cat recipe_book.txt
steak
$ git merge veg
Updating 25b1f57..e765cb4
Fast-forward
 recipe_book.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
$ cat recipe_book.txt
tofu
Jeff
  • 33
  • 5
  • yes as you said it was a fast-forward merge reverted and tried to use the --no-ff command when merging. However, while this time the content in the master branch remained present only small sections of the pizza-pasta were added. will re-write question to make it clearer and add the current state of affairs. – John Nov 15 '17 at 10:45
  • The `--no-ff` will only change how your git history looks. The merged file will be the same contents. Your assignment sounds like the "keep both" option that some GUI based conflict editors have but if you do your assignment as written, there will be no conflict when the `veg` branch is merged to `master`. – Jeff Nov 16 '17 at 14:26