If you see a git pull error on develop in Math repo, here's how to fix it

Hey all,

There’s a chance some of you will see this error message when trying to update your develop branch of Stan math:

Seans-MacBook-Pro ~/scm/cmdstan/stan/lib/stan_math (develop) $ git pull
Updating 4ffe6715eb..5f9d1650c3
error: Your local changes to the following files would be overwritten by merge:
	test/prob/normal_sufficient/normal_sufficient_test.hpp
	test/prob/wiener/wiener_test.hpp
Please commit your changes or stash them before you merge.
Aborting

If you do and don’t have any local changes to develop (you shouldn’t), you can fix this with this command:

git fetch
git reset --hard origin/develop

If anyone is curious, this is due to the .gitattributes file added recently that tells git to keep text files in the repo stored with LF line endings. The way that this functions is to apparently tell everyone using the repo about any files in the repo that don’t have those line endings and to present the status of the working directory as if those files have changes that you cannot stash or checkout until you commit. This is not the best user experience in my opinion but now that these two files have been converted in the repo, this shouldn’t happen anymore and future conversions should be automatic for everyone (including Windows users, who will get to see CRLF in their working directory while everything is LF in repo).

1 Like

Didn’t work for me. Here’s what I see:

[daniel@Daniels-MBP-2 math (develop)]$ git status
On branch develop
Your branch is up-to-date with 'origin/develop'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	modified:   test/prob/normal_sufficient/normal_sufficient_test.hpp
	modified:   test/prob/wiener/wiener_test.hpp

no changes added to commit (use "git add" and/or "git commit -a")
[daniel@Daniels-MBP-2 math (develop)]$ git reset --hard origin/develop
HEAD is now at 177ad420e3 Merge pull request #716 from rok-cesnovar/add_opencl_headers
[daniel@Daniels-MBP-2 math (develop)]$ git status
On branch develop
Your branch is up-to-date with 'origin/develop'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	modified:   test/prob/normal_sufficient/normal_sufficient_test.hpp
	modified:   test/prob/wiener/wiener_test.hpp

no changes added to commit (use "git add" and/or "git commit -a")
[daniel@Daniels-MBP-2 math (develop)]$ 

Update: I had to run

git fetch

before running

git reset --hard origin/develop

and now I’m ok.

1 Like

Yeah, sorry, was assuming you had tried to run git pull (which executes a fetch first). I will put the fetch in the original post instructions just in case.

Yeah, I did try a git pull --ff, but that failed. Maybe forcing fast forward didn’t actually fetch?

¯\_(ツ)_/¯

2 Likes