سؤال

We recently took over the management of a third party software and my first step when I now was assigned to the project was to push the software into a git repo directly from the live server.

Now I got a version of the project from a coworker: "Here you have the project-dir, I don't know exactly what files I have changed. I implemented feature XY. Please merge it into the repo somehow so we can deploy it to the staging server ...".

So now I'm in the need to merge the git repo vs. another version of the project and somehow I landed into linebreak-hell. It turns out that git thinks all files where changed. I played around with the various git settings (autocrlf), dos2unix, etc. and nothing worked.


After looking at the files it turns out I have the following situation:

In the original repo most of the files look like this:

  • The first 9 lines (copyright header) have unix linebreaks while the rest of the file has windows linebreaks.
  • Some files (I guess they where edited by the previous maintainer) have unix linebreaks only.

In the files I got from my coworker the situation is like this:

  • A few of the files are unchanged,
  • Most of the files (even if there is no other relevant change) have windows linebreaks all over (i.e. the copyright header is changed), also those now miss a newline at the end of the file.

Has anybody an easy idea how to clean that mess up?

I guess I could easily convert the whole codebase to unix style line endings, but the problem with that is that when I get a new version of the third-party app I'll have to care about all that mess again.

هل كانت مفيدة؟

المحلول

I ended up doing the following:

  1. cloned the repo,
  2. executed find . -type f -exec dos2unix {} \;,
  3. executed git add .,
  4. copied the files from my coworker over the checkout repo (overwriting anything),
  5. executed find . -type f -exec dos2unix {} \; again,
  6. executed git add -v -n . > /tmp/changed_files.

That way I ended up with a list of files that really had relevant changes so I could commit only those (quick&dirty solution without re-normalizing the whole repo).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top