-3

I try to decrease the number of commits in the history using the squash. I work alone, workflow is the simplest. I have not created any branches other than master.

This is the code and result:

$ git rebase -i 9852344
error: Your local changes to the following files would be overwritten by checkout:
        smtp_credentials.ini
Please commit your changes or stash them before you switch branches.
Aborting
error: could not detach HEAD

Do you have uncommitted changes? - No!

I don't understand what the system wants me to do. Please explain. The file smtp_credentials.ini is in gitingore. It has different versions local and on github.

Brian61354270
  • 8,690
  • 4
  • 21
  • 43
  • 4
    That error message is pretty explicit about what the problem is. You made uncommited changes to `smtp_credentials.ini`. These changes would be lost, so git is refusing to perform a rebase. Does doing what it told you to do not work? – Brian61354270 Feb 21 '21 at 18:00
  • I don;t understand what it wants. Please explain. The file smtp_credentials.ini is in gitingore. It has different versions local and on github. – Serhii Kushchenko Feb 21 '21 at 18:02
  • Do you have uncommited changes? - No! – Serhii Kushchenko Feb 21 '21 at 18:02
  • 3
    @SerhiiKushchenko Evidently you _do_ have uncommited changes, namely in `smtp_credentials.ini`. It being listed in your `.gitignore` is irrelevant if it's already being tracked. – Brian61354270 Feb 21 '21 at 18:03
  • 3
    Does this answer your question? [How to make Git "forget" about a file that was tracked but is now in .gitignore?](https://stackoverflow.com/questions/1274057/how-to-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore) –  Feb 21 '21 at 18:04
  • 2
    If you want to have the file in the repo but have it ignored at the same time, that doesn't work all that well, as you are seeing. What people usually do is have a `smtp_credentials.ini.template` tracked and `smtp_credentials.ini` (the one that's actually used) ignored. –  Feb 21 '21 at 18:09
  • I don't want the file smtp_credentials.ini to be removed form github! – Serhii Kushchenko Feb 21 '21 at 18:09
  • 1
    I think you have to move the file out of the way during the operation, you can put it back when you're done. –  Feb 21 '21 at 18:17
  • Yes, and the easiest way to "move the file out of the way" is to stash - i.e. exactly what the error message said to do in the first place. – Mark Adelsberger Feb 21 '21 at 18:30
  • to stash - IMHO too complicated for my case. To move the file out of the way during the operation and put it back when done - it helped, thanks a lot. – Serhii Kushchenko Feb 21 '21 at 19:53

2 Answers2

0

Let's post the answer explicitly. I think it will be useful to many people.

The file smtp_credentials.ini is in .gitignore; that changes nothing

It is not obvious to the git beginner. I couldn't figure it out anywhere online. The error message was not very helpful.

I supposed that adding the file to .gitignore and executing git rm --cached smtp_credentials.ini should be enough, but it is not enough.

To move the file out of the way during the operation and put it back when done

it worked, the comments by dratenik helped a lot.

  • "*It is not obvious to the git beginner. I couldn't figure it out anywhere online.*" Start with [`git help gitignore`](https://git-scm.com/docs/gitignore). The doc says: "Specifies intentionally **untracked** files to ignore" – phd Feb 21 '21 at 20:11
  • So what? I had different content in that file locally and on GitHub. No problems for a long time until I wanted to brush up the commits history. – Serhii Kushchenko Feb 21 '21 at 20:25
  • So that it doesn't matter if the file listed in `.gitignore` or not — the file is tracked and cannot be ignored. – phd Feb 21 '21 at 20:47
  • Yes but it is not obvious until you learn it the hard way – Serhii Kushchenko Feb 21 '21 at 21:29
  • 1
    This is why I say that the file name, `.gitignore`, is the wrong file name. The right file name is something like `.git-do-not-complain-about-these-files-if-they-are-untracked-files-and-do-not-automatically-add-them-with-en-masse-add-operations-in-that-case-either`, or something along those lines. But that file name is too ridiculous, so they went with the shorter but misleading one. – torek Feb 22 '21 at 01:55
-1

You keep saying that setup_credentials.ini is in .gitignore; that changes nothing. The only thing .gitignore does is to prevent an untracked file from being accidentally added to the index; this file is already in the index, so .gitignore has no effect on it.

More importantly - as others have noted, the error message is very explicit. It tells you the problem is changes in this file, and it tells you how to fix it (stash or commit the changes). Since you were trying to .gitignore the changes, I assume you don't intend to commit them; so stash them.

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52