git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Baptiste Fontaine <b@ptistefontaine.fr>
To: git@vger.kernel.org
Subject: No warning when checking-out a branch with a file that already exists but is not indexed in the current branch
Date: Tue, 27 Oct 2020 13:39:16 +0100	[thread overview]
Message-ID: <ED4DFC77-2135-476E-AA22-7E887B25565D@ptistefontaine.fr> (raw)

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

                 reply	other threads:[~2020-10-27 13:03 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ED4DFC77-2135-476E-AA22-7E887B25565D@ptistefontaine.fr \
    --to=b@ptistefontaine.fr \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).