Pregunta

I’m using git for keeping track of the development of a small web site of mine. I have two branches at the moment:

  1. a master branch with code that is (supposedly) ready for deployment
  2. a dev branch where I try out things until I think they are ready for deployment

In order to get used to good habits in case of upscaling the development to more people I usually merge the master branch with the dev branch before checking out the master branch and merging the dev into it – so as to be able to resolve any conflicts in the dev branch instead of on the master.

Last time i did so, some of the code just disappeared (css code for id="all_text", see code further down). I figured that this was because the code was absent in the master branch and because I was moving the master code into the dev branch (but it’s not how I remember it to behave), so I undid the merge (git reset --merge; I’m on git 1.7.0.3), checked out the master branch and merged it with the dev branch. Same result – most of the code in the #all_text css disappeared.

I’m at loss as to why this is happening. The most recent changes are on the dev branch so they should reasonably be carried over in a merge, instead they are deleted.

Is there any way to solve this without doing the ugly hack of copying the contents of the documents in dev manually to master?

Dev content (index.css)

body {
    margin:0;
    padding:0;
}

/* attributes for the <div> that encapsules the h1 and the encouragement */

#all_text {
    position: relative;
    height: 50%;
    width: 70%;
    margin-top:8em;
    margin-left:auto;
    margin-right:auto;
    text-align: center;

//  background-color: yellow; // Trace code to better see the design
}

h1 {
    position: relative;
    text-align: center;

    font-size: 700%;
    color: #4970A8;
/*  color: #5AA0FF; */
    text-shadow: 4px 4px 8px gray;

//  background-color: green; // Trace code to better see the design
}

div.encouragement {
    position: relative;
    width: 70%;
    bottom: 25px;

    color: #4970A8;
    font-size: 170%;

//  background-color: red; // Trace code to better see the design
}

Master content (index.css)

#all_text {
    position: relative;
}

h1 {
    color: #4970A8;
/*  color: #5AA0FF; */
    text-align: center;
/*  text-vertica-align: center; */
    font-size: 700%;
    position: relative;
    top:30%;

    text-shadow: 4px 4px 8px gray;
}

div.encouragement {
    color: #4970A8;
    text-align: center;
    font-size: 150%;
/*  position: absolute;
    top: 5%m;
    left:7%em; */
/*  text-shadow: 2px 2px 8px gray; */
}

Merged content (index.css)

#all_text {
    position: relative;
}

h1 {
<<<<<<< HEAD
    position: relative;
    text-align: center;

    font-size: 700%;
    color: #4970A8;
/*  color: #5AA0FF; */
    text-shadow: 4px 4px 8px gray;

//  background-color: green; // Trace code to better see the design
}

div.encouragement {
    position: relative;
    width: 70%;
    bottom: 25px;

    color: #4970A8;
    font-size: 170%;

//  background-color: red; // Trace code to better see the design
=======
    color: #4970A8;
/*  color: #5AA0FF; */
    text-align: center;
/*  text-vertica-align: center; */
    font-size: 700%;
    position: relative;
    top:30%;

    text-shadow: 4px 4px 8px gray;
}

div.encouragement {
    color: #4970A8;
    text-align: center;
    font-size: 150%;
/*  position: absolute;
    top: 5%m;
    left:7%em; */
/*  text-shadow: 2px 2px 8px gray; */
>>>>>>> master
}

What happened to most of the text in the #all_text{…} section?

Thanks on beforehand.


Update: Added the merge-base (according to dyng’s instructions).

Running git show $(git merge-base dev master) gives me this:

diff --git a/www/index.css b/www/index.css
index b837a87..d8c48ef 100644
--- a/www/index.css
+++ b/www/index.css
@@ -1,25 +1,44 @@
+body {
+       margin:0;
+       padding:0;
+}
+
+/* attributes for the <div> that encapsules the h1 and the encouragement */
 #all_text {
        position: relative;
+       height: 50%;
+       width: 70%;
+       margin-top:8em;
+       margin-left:auto;
+       margin-right:auto;
+       text-align: center;
+               
+//     background-color: yellow; // Trace code to better see the design
 }

+
 h1 {
        color: #4970A8;
 /*     color: #5AA0FF; */
        text-align: center;
-/*     text-vertica-align: center; */
+       display: inline-block;
        font-size: 700%;
        position: relative;
-       top:30%;
+       left:0.5em;
+

        text-shadow: 4px 4px 8px gray;
+               
+//     background-color: green; // Trace code to better see the design
 }

-div.encouragement {
+span.encouragement {
        color: #4970A8;
-       text-align: center;
-       font-size: 150%;
-/*     position: absolute;
-       top: 5%m;
-       left:7%em; */
-/*     text-shadow: 2px 2px 8px gray; */
+       font-size: 170%;
+       position: relative;
+       top: 3em;
+       right:18em; 
+
+
+//     background-color: red; // Trace code to better see the design
 }
\ No newline at end of file
¿Fue útil?

Solución

I undid the last commit (the last push) directly on the server and then fetched/pulled it to the local master.

It's the key to your problem. Revert that commit in master by

git checkout master
git revert <sha1_of_that_commit>

then merge will work fine.

But as VonC said, merge/pull master to dev is not a so good idea, git rebase or git pull --rebase should be better.

Otros consejos

I usually merge the master branch with the dev branch before checking out the master branch and merging the dev into it

In order to avoid those merge issues, it would be better to:

  • rebase dev on top of master
  • before merging dev to master

That way, you reapply (rebase) your changes on top of master, making any "disappearance" of your dev code unlikely.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top