2

I have 2 branches: master and develop.

In develop I rename the file with git:

git mv Myfile.txt myfile.txt

git add . 

git commit -m "Rename file Myfile to myfile"

Now I try to switch branch.

git checkout master

And get an error:

error: The following untracked working tree files would be overwritten by checkout: Myfile.txt Please move or remove them before you can switch branches. Aborting

  1. File Myfile.txt no longer exists in the working directory.
  2. I try to change case sensitive settings by git config core.ignorecase, not works.
  3. I'm working on Ubuntu 16.04

Problem solves only when I return a file to its old name.

Can anyone suggest how to do this in a right way?

UPDATE:

It looks like this issue related to my dev machine - Ubuntu 16.04. It running using Vagrant. All git commands i run when connecting to the machine through ssh. From my MacBook command line, everything works as expected.

Denys Kurbatov
  • 143
  • 2
  • 10
  • see https://stackoverflow.com/a/7846174/1479895, `git add -A` could be the right command to update the index – Anton Belev Feb 13 '19 at 13:37
  • on git mv Myfile.txt myfile.txt give this error fatal: bad source, source=Myfile.txt, destination=myfile.txt how can you move file using git. – Ashok Feb 13 '19 at 13:39
  • @AshokPatidar this error raise when `core.ignorecase` if `false` – Denys Kurbatov Feb 13 '19 at 13:49
  • @AntonBelev not work ( – Denys Kurbatov Feb 13 '19 at 13:50
  • `git rm --cached Myfile.txt` ? – alberand Feb 13 '19 at 14:14
  • @Denys Kurbatov what do you get when you do `git status` after you have moved the file and before commiting? – Ezwig Feb 13 '19 at 14:14
  • Why the `git add .` between `git mv` and `git commit`? `git mv` already puts the move in the cache, so the `git add` would only serve to add other changes in your sandbox to the same commit, which, IMHO, confuses things, especially with the commit message you show. – joanis Feb 13 '19 at 14:27
  • @A.Albershteyn `git rm --cached Myfile.txt` file not exists ( – Denys Kurbatov Feb 13 '19 at 15:01
  • @joanis Commit message have no sense in current case, i showed here just for simplicity. – Denys Kurbatov Feb 13 '19 at 15:02
  • @DenysKurbatov but why the `git add .`? – joanis Feb 13 '19 at 15:13
  • @joanis OK, I made a mistake by typing this command, but you think that problem will solve without this command? – Denys Kurbatov Feb 13 '19 at 15:15
  • Suggestions: after `git mv`, do `git status` and `ls` and show us the output. The answer might be there. Again, after `git commit`, show output of `git status` and `ls`. For what it's worth, the behaviour you see is unexpected. When I try to reproduce your problem it works fine without error. – joanis Feb 13 '19 at 15:16
  • @DenysKurbatov removing `git add .` should make no difference, but it seems worth trying. I'm just trying to reproduce your problem and figure out what is the minimal reproducible procedure, and I'm not succeeding. So it's easier if we remove irrelevant commands from the procedure. – joanis Feb 13 '19 at 15:18
  • @joanis after `git move` - `git status` output - `renamed: Myfile.txt -> myfile.txt` – Denys Kurbatov Feb 13 '19 at 15:21

0 Answers0