From: Phillip Wood <phillip.wood123@gmail.com>
To: wh <microrffr@gmail.com>, phillip.wood@dunelm.org.uk
Cc: git@vger.kernel.org, "Junio C Hamano" <gitster@pobox.com>,
"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: Re: [BUG] rebase --interactive silently overwrites ignored files
Date: Thu, 2 May 2019 16:45:46 +0100 [thread overview]
Message-ID: <3bf0f04d-83d4-ef13-8e19-a679b4153793@gmail.com> (raw)
In-Reply-To: <CAL_tzDFQQtDYMStN+RDVYN_TzJmO+kufMhG9PGHwvsUWREpgWQ@mail.gmail.com>
Hi wh
On 14/04/2019 02:59, wh wrote:
> Thanks for the info about the upcoming "precious" attribute. Looks useful.
>
> I didn't get the impression that Git normally overwrites ignored
> files. I ran some more experiments:
>
> git rebase FETCH_HEAD # bails
> git rebase -i FETCH_HEAD # overwrites
> git merge FETCH_HEAD # bails
> git reset --keep FETCH_HEAD # bails
> git reset --merge FETCH_HEAD # bails
> git checkout FETCH_HEAD # overwrites
> # without feature 2 locally:
> git merge FETCH_HEAD # overwrites, fast-forwards
> git merge --no-ff FETCH_HEAD # bails
I've had a look at the rebase -i code and I think it only overwrites
ignored files when it is fast-forwarding. This matches what merge does
when fast-forwarding but I'm not convinced either of them should be
doing this by default (I think checkout doing it is probably asking for
trouble), as you point out most operations preserve ignored files. When
pull fast-forwards it does not overwrite ignored files.
Both checkout and merge have an undocumented --overwrite-ignore option
which is on by default. Checkout and fast-forward merges overwriting
ignored files dates back a long way to commit 1127148089 ("Loosen
"working file will be lost" check in Porcelain-ish", 2006-12-04). There
does not seem to have been much discussion of changing the semantics of
ignored files around the patches that implemented this [1,2]. There is a
brief mention of doing it in this thread [3] but no one seems to comment
on the idea as far as I can see. Before this change ignored files were
just ignored by status and add but otherwise treated like any other
untracked file.
I'll put a patch together to fix rebase -i, I'd like to see the defaults
for merge and checkout changed but I'm not sure that would be popular.
It does seem like surprising behavior though when most operations try to
preserve untracked files.
Best Wishes
Phillip
[1]
https://public-inbox.org/git/7vlklnkv39.fsf@assigned-by-dhcp.cox.net/T/#u
[2]
https://public-inbox.org/git/7vbqmjkuzd.fsf@assigned-by-dhcp.cox.net/T/#u
[3]https://public-inbox.org/git/Pine.LNX.4.64.0610081657400.3952@g5.osdl.org/
> On Fri, Apr 12, 2019 at 9:30 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
>>
>> Hi
>>
>> On 12/04/2019 00:56, wh wrote:
>>> I'm using git 2.20.1 from Debian. Git is usually careful not to
>>> overwrite untracked files, including ignored files.
>>
>> Git normally overwrites ignored files, so I think in your example rebase
>> -i is working as expected, I'm surprised that the am based rebase does
>> not overwrite the ignored file. There has been some discussion about
>> introducing 'precious' files that are ignored but protected in the same
>> way as untracked files [1].
>>
>> Best Wishes
>>
>> Phillip
>>
>> [1] https://public-inbox.org/git/20190409102649.22115-1-pclouds@gmail.com/
>>
>> But interactive
>>> rebase doesn't detect this (non-interactive rebase works fine).
>>>
>>> Reproduction:
>>> -----
>>>
>>> #!/bin/sh
>>> mkdir upstream
>>> cd upstream
>>> git init
>>> echo 1 >feature-1
>>> git add feature-1
>>> git commit -m "feature 1"
>>>
>>> cd ..
>>> git clone upstream local
>>> cd local
>>> # write some tools for our own convenience
>>> echo ours >tools
>>> echo /tools >>.git/info/exclude
>>> # start working on a feature
>>> git checkout -b f2
>>> echo wip >feature-2
>>> git add feature-2
>>> git commit -m "wip"
>>>
>>> cd ../upstream
>>> # official tools are available
>>> echo theirs >tools
>>> git add tools
>>> git commit -m "tools"
>>>
>>> cd ../local
>>> git fetch ../upstream master
>>>
>>> # this would be okay
>>> #git rebase FETCH_HEAD
>>>
>>> # problem: overwrites tools silently
>>> GIT_EDITOR=true git rebase -i FETCH_HEAD
>>>
>>> cat tools
>>>
>>> -----
>>>
>>> Expected: `git rebase -i` fails because it would have to overwrite the
>>> untracked "tools" file. Contents of tools file remains `ours`.
>>>
>>> Actual: Contents of tools file becomes `theirs`.
>>>
next prev parent reply other threads:[~2019-05-02 15:45 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-11 23:56 [BUG] rebase --interactive silently overwrites ignored files wh
2019-04-12 16:30 ` Phillip Wood
2019-04-14 1:59 ` wh
2019-04-14 13:24 ` Phillip Wood
2019-05-02 15:45 ` Phillip Wood [this message]
2019-05-02 16:22 ` Duy Nguyen
2019-05-05 4:02 ` Junio C Hamano
2019-05-07 14:03 ` Phillip Wood
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=3bf0f04d-83d4-ef13-8e19-a679b4153793@gmail.com \
--to=phillip.wood123@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=microrffr@gmail.com \
--cc=pclouds@gmail.com \
--cc=phillip.wood@dunelm.org.uk \
/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).