git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* No warning when checking-out a branch with a file that already exists but is not indexed in the current branch
@ 2020-10-27 12:39 Baptiste Fontaine
  0 siblings, 0 replies; only message in thread
From: Baptiste Fontaine @ 2020-10-27 12:39 UTC (permalink / raw)
  To: git

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-10-27 13:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-27 12:39 No warning when checking-out a branch with a file that already exists but is not indexed in the current branch Baptiste Fontaine

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).