No warning when checking-out a branch with a file that already exists but is not indexed in the current branch

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I’m not sure if this is a bug or expected behavior:

1. Create a sample repo:

  % git init
  % touch a.txt
  % git add a.txt
  % git commit -m "add a.txt"

2. Create a new branch, in which you add foo.txt:

  % git checkout -b devel
  % echo "Something" > foo.txt
  % git add foo.txt
  % git commit -m "Write something in foo.txt"

3. Go back to the first branch and create an ignored file with the
   same name:

  % git checkout master
  % echo foo.txt > .gitignore
  % git add .gitignore
  % git commit -m "ignore foo.txt"
  % echo "Something else" > foo.txt
  % cat foo.txt
  Something else

4. Check-out the branch with the indexed file:

  % git checkout devel # <-- no warning here
  % cat foo.txt
  Something

5. Check-out again the branch without the indexed file:

  % git checkout master
  % cat foo.txt
  cat: foo.txt: No such file or directory

The non-indexed file is now gone, and there was no warning when git
“took over it” in step 4. As far as I know there’s no way to retrieve
the "Something else" content.

I’m using git version 2.28.0.

I came to this situation on a repository in which I had a ROADMAP.md
file on master, which I `git rm --cached` and added to .gitignore on
devel. I later modified this file, but it was removed when I switched
on master.


Regards,

Baptiste Fontaine



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux