mydoglixu
mydoglixu

Reputation: 944

Sourcetree changes commits when merging

I'm using SourceTree to manage my git. What I'm trying to do is merge a branch with changes (master-k) into master. Everything looks just fine in each commit on the branch, but then during the merge, the whole file is getting changed.

Note: the master-k branch came from another user on a mac, and might have used to merge the Pull request. I'm on Windows 10 using Sourcetree.

Here's a screenshot of the branch with commits. Note that the diff shown has individual lines: enter image description here

And here is a screenshot during the merge (has conflicts to resolve): enter image description here

You can see above that the diff is basically everything in style.css.

A couple of things I have tried:

The ignore whitespace was a problem for me in the past- it was making my diffs on the whole file. Once I found this checkbox, everything was fine. I made sure it was off now, but this merge is still giving me a problem.

Upvotes: 0

Views: 1172

Answers (2)

mydoglixu
mydoglixu

Reputation: 944

Shout out to LightBender for their first answer above. I encountered another similar issue today which led me to finding yet another reason for the entire file showing as a diff.

Same symptoms, different reason.

The problem occurred because I was using compass on a Windows machine. On Windows, the Unix line endings aren't enabled by default.

I found this thread which solved it for me: https://github.com/Compass/compass/issues/949

Solution is to add this:

sass_options = {:unix_newlines => true}

to my config.rb file. Then recompile using

compass compile

And the output came through perfectly! Only the actual line diffs showed instead of the whole file.

Hope this helps someone!

Upvotes: 0

LightBender
LightBender

Reputation: 4263

It looks like you've got two separate issues going on here

Line Endings and Whitespace

Make sure that your auto whitespace is set to either input or auto if you're on Windows. Depending on if you want to preserve the Unix-style or use Windows-style in your working directory. Both will commit Unix-style line endings.

Then normalize your line endings to save yourself headaches in the future. This is fairly well documented, so I won't go into it here, but this is a good guide.

Note that changing your diff style does not affect the files on disk or the way git performs a merge, it only changes the way the diff tool displays the changes. I generally recommend leaving the whitespace visible because it will show you where you are making unnecessary changes that can cause you conflicts later.

Dealing with artifacts

Your style.css file is compiled from sass code, so it is technically an artifact, not code proper.

Whether or not to include this in your repo largely depends on your workflow and deployment process. In an ideal world, you'd compile your CSS during the deployment process and not store the artifacts in the repo. Since we don't live in an ideal world, I'll just touch briefly on handling the weirdness that comes with artifacts stored in the repo.

When you've got an artifact like this, resolving the merge, even if successful, will at the very least break the map data in the file. This will only compound if you start producing minified versions of the CSS as well. Fortunately, the way to deal with this is simple, and resolve any conflicts the source code, then re-compile the artifacts and add them to the commit.

The sequence of actions will run something like this:

git checkout master-k
git merge master

resolve code conflicts here

npm run buildcssjob # or similar

test everything

git add style.css
git commit
git checkout master
git merge [--no-ff] master-k

and you're done.

Upvotes: 1

Related Questions