threads / discuss / 54516

Proposal: "unadd" command / alias.

Subject: Proposal: "unadd" command / alias.

## tl;dr

12 messages between Oct 27, 2020 and Oct 29, 2020.

replies: 11people: 6as markdown or json

Filipp Bakanov· Oct 27, 2020, 20:10 UTC · lore
Hi! I suggest to add "unadd" command, that will undo a git add command.
git unadd path/to/file
It will be an alias to:
git reset HEAD -- path/to/file

The motivation is that I always forget syntax and have to google each time I want to undo accidentally added files. Unadd is just much easier to remember and quite obvious.

Junio C Hamano· Oct 27, 2020, 20:32 UTC · re: Filipp Bakanov · lore

Re: Proposal: "unadd" command / alias.

Filipp Bakanov <filipp@bakanov.su> writes:
Show 11 quoted lines
> Hi! I suggest to add "unadd" command, that will undo a git add command.
>
> git unadd path/to/file
>
> It will be an alias to:
>
> git reset HEAD -- path/to/file
>
> The motivation is that I always forget syntax and have to google each
> time I want to undo accidentally added files. Unadd is just much
> easier to remember and quite obvious.
The alias is for you to do the above, I think.
Theodore Y. Ts'o· Oct 27, 2020, 21:56 UTC · re: Junio C Hamano · lore

Re: Proposal: "unadd" command / alias.

On Tue, Oct 27, 2020 at 01:32:50PM -0700, Junio C Hamano wrote:
Show 15 quoted lines
> Filipp Bakanov <filipp@bakanov.su> writes:
> 
> > Hi! I suggest to add "unadd" command, that will undo a git add command.
> >
> > git unadd path/to/file
> >
> > It will be an alias to:
> >
> > git reset HEAD -- path/to/file
> >
> > The motivation is that I always forget syntax and have to google each
> > time I want to undo accidentally added files. Unadd is just much
> > easier to remember and quite obvious.
> 
> The alias is for you to do the above, I think.
Filipp,
Indeed, I have a similar alias in my ~/.gitconfig
[alias]
	revert-file = checkout HEAD --
Adding
[alias]
	unadd = reset HEAD --

to your .gitconfig would do what you want. As a BTW, my favorite alias is:

   lgt = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit
Sample usage: "git lgt origin.." or "git lgt -10".
Cheers,
					- Ted
Filipp Bakanov· Oct 27, 2020, 22:02 UTC · re: Theodore Y. Ts'o · lore

Re: Proposal: "unadd" command / alias.

>> Indeed, I have a similar alias in my ~/.gitconfig

Why not just add it to git by default for everybody? revert-file is also ok, anything except `checkout HEAD --` will be good.

On Wed, 28 Oct 2020 at 00:56, Theodore Y. Ts'o <tytso@mit.edu> wrote:
Show 40 quoted lines
>
> On Tue, Oct 27, 2020 at 01:32:50PM -0700, Junio C Hamano wrote:
> > Filipp Bakanov <filipp@bakanov.su> writes:
> >
> > > Hi! I suggest to add "unadd" command, that will undo a git add command.
> > >
> > > git unadd path/to/file
> > >
> > > It will be an alias to:
> > >
> > > git reset HEAD -- path/to/file
> > >
> > > The motivation is that I always forget syntax and have to google each
> > > time I want to undo accidentally added files. Unadd is just much
> > > easier to remember and quite obvious.
> >
> > The alias is for you to do the above, I think.
>
> Filipp,
>
> Indeed, I have a similar alias in my ~/.gitconfig
>
> [alias]
>         revert-file = checkout HEAD --
>
> Adding
>
> [alias]
>         unadd = reset HEAD --
>
> to your .gitconfig would do what you want.  As a BTW, my favorite
> alias is:
>
>    lgt = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit
>
> Sample usage: "git lgt origin.." or "git lgt -10".
>
> Cheers,
>
>                                         - Ted
Theodore Y. Ts'o· Oct 27, 2020, 22:54 UTC · re: Filipp Bakanov · lore

Re: Proposal: "unadd" command / alias.

On Wed, Oct 28, 2020 at 01:02:11AM +0300, Filipp Bakanov wrote:
> >> Indeed, I have a similar alias in my ~/.gitconfig
> 
> Why not just add it to git by default for everybody? revert-file is
> also ok, anything except `checkout HEAD --` will be good.

Because everyone may have their own favorite aliases? Just because *I* have the following aliases doesn't mean that everyone else would find them useful.

[alias]
	new = !gitk --all --not ORIG_HEAD
	dw = diff --stat --summary
	di = diff --stat --summary --cached
	dc = describe --contains
	revert-file = checkout HEAD --
	l  = log --pretty=format:'%Cred%h%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit
	lr = log --reverse --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit
	rl  = log -g --pretty=format:'%Cred%h%Creset %gd %gs %Cgreen(%gr)%Creset %s' --abbrev-commit
	rl1  = log -g --date=relative --pretty=format:'%Cred%h%Creset %gs %Cgreen%gd%Creset %s' --abbrev-commit
	lg  = log --graph --pretty=format:'%Cred%h%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit
	lgt = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit
	rlt = log -g --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit
	lgt-nc = log --graph --pretty=format:'%h -%d %s (%cr)' --abbrev-commit
	st = status -s
	recent = for-each-ref --count=15 --sort=-committerdate refs/heads/ --format='%(committerdate:short) %(refname:short)'
	gerrit-clone = !bash ggh gerrit-clone
	start = !bash ggh start
	upload = !bash ggh upload
	prune-branches = !bash ggh prune-branches
	fixes = log -1 --pretty=fixes

I have a huge number of bash aliases, and that doesn't mean everyone else should have those bash aliases. For that matter, I have the following in ~/bin/git-rp-ext4 so that I can type "git rp-ext4 tags/ext4_for_linus". But that doesn't mean this script is right for everyone....

Cheers,
					- Ted
#!/bin/sh

START=origin URL=git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git END=""

print_help ()
{
    PROG=$(basename "$0")
    echo "Usage: $PROG [-n] [--start <START COMMIT>] [--url <URL] [<END COMMIT>]"
    exit 1
}
while [ "$1" != "" ]; do
    case $1 in
	--start) shift
		 START="$1"
		 ;;
	--url) shift
	       URL="$1"
	       ;;
	-n) NO_ACTION="echo" ;;
	-*) print_help ;;
	*)
	    if test -n "$END"
	    then
		print_help
	    else
		END="$1"
	    fi
	    ;;
    esac
    shift
done
$NO_ACTION git request-pull "$START" "$URL" "$END"
Filipp Bakanov· Oct 27, 2020, 23:14 UTC · re: Theodore Y. Ts'o · lore

Re: Proposal: "unadd" command / alias.

It's the matter of UX. If many users have to make an alias for the same unclear command, at least it's a point to think about making this particular command more convenient. As far as I remember, some aliases were already added to git by default. What's bad with adding a popular (among many users) aliases, if they improve UX and make life easier?

On Wed, 28 Oct 2020 at 01:54, Theodore Y. Ts'o <tytso@mit.edu> wrote:
Show 80 quoted lines
>
> On Wed, Oct 28, 2020 at 01:02:11AM +0300, Filipp Bakanov wrote:
> > >> Indeed, I have a similar alias in my ~/.gitconfig
> >
> > Why not just add it to git by default for everybody? revert-file is
> > also ok, anything except `checkout HEAD --` will be good.
>
> Because everyone may have their own favorite aliases?  Just because
> *I* have the following aliases doesn't mean that everyone else would
> find them useful.
>
> [alias]
>         new = !gitk --all --not ORIG_HEAD
>         dw = diff --stat --summary
>         di = diff --stat --summary --cached
>         dc = describe --contains
>         revert-file = checkout HEAD --
>         l  = log --pretty=format:'%Cred%h%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit
>         lr = log --reverse --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit
>         rl  = log -g --pretty=format:'%Cred%h%Creset %gd %gs %Cgreen(%gr)%Creset %s' --abbrev-commit
>         rl1  = log -g --date=relative --pretty=format:'%Cred%h%Creset %gs %Cgreen%gd%Creset %s' --abbrev-commit
>         lg  = log --graph --pretty=format:'%Cred%h%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit
>         lgt = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit
>         rlt = log -g --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit
>         lgt-nc = log --graph --pretty=format:'%h -%d %s (%cr)' --abbrev-commit
>         st = status -s
>         recent = for-each-ref --count=15 --sort=-committerdate refs/heads/ --format='%(committerdate:short) %(refname:short)'
>         gerrit-clone = !bash ggh gerrit-clone
>         start = !bash ggh start
>         upload = !bash ggh upload
>         prune-branches = !bash ggh prune-branches
>         fixes = log -1 --pretty=fixes
>
> I have a huge number of bash aliases, and that doesn't mean everyone
> else should have those bash aliases.  For that matter, I have the
> following in ~/bin/git-rp-ext4 so that I can type "git rp-ext4
> tags/ext4_for_linus".  But that doesn't mean this script is right for
> everyone....
>
> Cheers,
>
>                                         - Ted
>
> #!/bin/sh
>
> START=origin
> URL=git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git
> END=""
>
> print_help ()
> {
>     PROG=$(basename "$0")
>     echo "Usage: $PROG [-n] [--start <START COMMIT>] [--url <URL] [<END COMMIT>]"
>     exit 1
> }
>
> while [ "$1" != "" ]; do
>     case $1 in
>         --start) shift
>                  START="$1"
>                  ;;
>         --url) shift
>                URL="$1"
>                ;;
>         -n) NO_ACTION="echo" ;;
>         -*) print_help ;;
>         *)
>             if test -n "$END"
>             then
>                 print_help
>             else
>                 END="$1"
>             fi
>             ;;
>     esac
>     shift
> done
>
> $NO_ACTION git request-pull "$START" "$URL" "$END"
>
Philip Oakley· Oct 28, 2020, 11:00 UTC · re: Filipp Bakanov · lore

Re: Proposal: "unadd" command / alias.

On 27/10/2020 23:14, Filipp Bakanov wrote:
Show 6 quoted lines
> It's the matter of UX. If many users have to make an alias for the
> same unclear command, at least it's a point to think about making this
> particular command more convenient. As far as I remember, some aliases
> were already added to git by default.
> What's bad with adding a popular (among many users) aliases, if they
> improve UX and make life easier?

One option maybe to curate a few of the more popular aliases within a contrib/aliases file/directory.

Not sure how best to add comments into the alias file so folks can remember what they are really meant to do, or where they copied them from.

Philip
Show 79 quoted lines
>
> On Wed, 28 Oct 2020 at 01:54, Theodore Y. Ts'o <tytso@mit.edu> wrote:
>> On Wed, Oct 28, 2020 at 01:02:11AM +0300, Filipp Bakanov wrote:
>>>>> Indeed, I have a similar alias in my ~/.gitconfig
>>> Why not just add it to git by default for everybody? revert-file is
>>> also ok, anything except `checkout HEAD --` will be good.
>> Because everyone may have their own favorite aliases?  Just because
>> *I* have the following aliases doesn't mean that everyone else would
>> find them useful.
>>
>> [alias]
>>         new = !gitk --all --not ORIG_HEAD
>>         dw = diff --stat --summary
>>         di = diff --stat --summary --cached
>>         dc = describe --contains
>>         revert-file = checkout HEAD --
>>         l  = log --pretty=format:'%Cred%h%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit
>>         lr = log --reverse --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit
>>         rl  = log -g --pretty=format:'%Cred%h%Creset %gd %gs %Cgreen(%gr)%Creset %s' --abbrev-commit
>>         rl1  = log -g --date=relative --pretty=format:'%Cred%h%Creset %gs %Cgreen%gd%Creset %s' --abbrev-commit
>>         lg  = log --graph --pretty=format:'%Cred%h%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit
>>         lgt = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit
>>         rlt = log -g --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit
>>         lgt-nc = log --graph --pretty=format:'%h -%d %s (%cr)' --abbrev-commit
>>         st = status -s
>>         recent = for-each-ref --count=15 --sort=-committerdate refs/heads/ --format='%(committerdate:short) %(refname:short)'
>>         gerrit-clone = !bash ggh gerrit-clone
>>         start = !bash ggh start
>>         upload = !bash ggh upload
>>         prune-branches = !bash ggh prune-branches
>>         fixes = log -1 --pretty=fixes
>>
>> I have a huge number of bash aliases, and that doesn't mean everyone
>> else should have those bash aliases.  For that matter, I have the
>> following in ~/bin/git-rp-ext4 so that I can type "git rp-ext4
>> tags/ext4_for_linus".  But that doesn't mean this script is right for
>> everyone....
>>
>> Cheers,
>>
>>                                         - Ted
>>
>> #!/bin/sh
>>
>> START=origin
>> URL=git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git
>> END=""
>>
>> print_help ()
>> {
>>     PROG=$(basename "$0")
>>     echo "Usage: $PROG [-n] [--start <START COMMIT>] [--url <URL] [<END COMMIT>]"
>>     exit 1
>> }
>>
>> while [ "$1" != "" ]; do
>>     case $1 in
>>         --start) shift
>>                  START="$1"
>>                  ;;
>>         --url) shift
>>                URL="$1"
>>                ;;
>>         -n) NO_ACTION="echo" ;;
>>         -*) print_help ;;
>>         *)
>>             if test -n "$END"
>>             then
>>                 print_help
>>             else
>>                 END="$1"
>>             fi
>>             ;;
>>     esac
>>     shift
>> done
>>
>> $NO_ACTION git request-pull "$START" "$URL" "$END"
>>
Pratyush Yadav· Oct 28, 2020, 13:07 UTC · re: Filipp Bakanov · lore

Re: Proposal: "unadd" command / alias.

On Tue, Oct 27 2020, Filipp Bakanov wrote:
Show 11 quoted lines
> Hi! I suggest to add "unadd" command, that will undo a git add command.
>
> git unadd path/to/file
>
> It will be an alias to:
>
> git reset HEAD -- path/to/file
>
> The motivation is that I always forget syntax and have to google each
> time I want to undo accidentally added files. Unadd is just much
> easier to remember and quite obvious.
Why do you need to Google when `git status` tells you how to do it?
    $ touch foo
    $ git add foo
    $ git status
    On branch master
    Your branch is up to date with 'origin/master'.
    Changes to be committed:
      (use "git restore --staged <file>..." to unstage)
    	new file:   foo
    
    $ git restore --staged foo
    $ git status
    On branch master
    Your branch is up to date with 'origin/master'.
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
    	foo
    nothing added to commit but untracked files present (use "git add" to track)
-- 
Regards,
Pratyush Yadav
Filipp Bakanov· Oct 28, 2020, 13:56 UTC · re: Pratyush Yadav · lore

Re: Proposal: "unadd" command / alias.

Thank you for mentioning git restore.
Answering to your question, my brain filtered all the output of git
status except "modified: ..."
There are multiple reasons:
 - command named restore. I don't know what it will restore. Maybe it
will restore a clean version? Maybe it will remove all my changes? I
don't want to risk.
 - I don't know what means "unstage". I didn't run "git stage" to add
my files, why should I run git restore --staged to undo git add? If
command would be named "git unadd" and description would be "undo git
add", it would be more obvious than git restore --staged or git reset.
 I asked my friends, no one remembered how to undo git add. One said:
 " - May be it's git reset but I'm not sure, need to check before
apply". And he agreed that "git unadd" would be a more obvious.
On Wed, 28 Oct 2020 at 16:07, Pratyush Yadav <me@yadavpratyush.com> wrote:
Show 41 quoted lines
>
> On Tue, Oct 27 2020, Filipp Bakanov wrote:
>
> > Hi! I suggest to add "unadd" command, that will undo a git add command.
> >
> > git unadd path/to/file
> >
> > It will be an alias to:
> >
> > git reset HEAD -- path/to/file
> >
> > The motivation is that I always forget syntax and have to google each
> > time I want to undo accidentally added files. Unadd is just much
> > easier to remember and quite obvious.
>
> Why do you need to Google when `git status` tells you how to do it?
>
>     $ touch foo
>     $ git add foo
>     $ git status
>     On branch master
>     Your branch is up to date with 'origin/master'.
>
>     Changes to be committed:
>       (use "git restore --staged <file>..." to unstage)
>         new file:   foo
>
>     $ git restore --staged foo
>     $ git status
>     On branch master
>     Your branch is up to date with 'origin/master'.
>
>     Untracked files:
>       (use "git add <file>..." to include in what will be committed)
>         foo
>
>     nothing added to commit but untracked files present (use "git add" to track)
>
> --
> Regards,
> Pratyush Yadav
Junio C Hamano· Oct 28, 2020, 23:44 UTC · re: Filipp Bakanov · lore

Re: Proposal: "unadd" command / alias.

Filipp Bakanov <filipp@bakanov.su> writes:
Show 11 quoted lines
> Hi! I suggest to add "unadd" command, that will undo a git add command.
>
> git unadd path/to/file
>
> It will be an alias to:
>
> git reset HEAD -- path/to/file
>
> The motivation is that I always forget syntax and have to google each
> time I want to undo accidentally added files. Unadd is just much
> easier to remember and quite obvious.

I am not sure if the behaviour of the "git reset HEAD -- path" is what people would imagine what "unadd" would do, actually. For example, with this sequence:

    $ edit file
    $ git add file
    $ edit file
    $ git add file
    $ git unadd file

what would be the natural expectation of users after the last "unadd" step? Should it have the result of the first 'add'? Should another "git unadd file" bring the index back to the state before the first 'add' was run?

There is no such ambiguity to "reset HEAD -- path". It tells exactly what contents you want to have in the index for the path (i.e. the same as what is in HEAD). There is no "go back to the state before the last add", and there is no false hint that such a thing might exist.

So, I do not think it is a good idea to even call it "unadd", let alone adding an alias that is used outside your immediate circle where you can explain what it exactly means to "unadd" by your definition.

Konstantin Tokarev· Oct 28, 2020, 12:13 UTC · re: Filipp Bakanov · lore

Re: Proposal: "unadd" command / alias.

27.10.2020, 23:10, "Filipp Bakanov" <filipp@bakanov.su>:
Show 7 quoted lines
> Hi! I suggest to add "unadd" command, that will undo a git add command.
>
> git unadd path/to/file
>
> It will be an alias to:
>
> git reset HEAD -- path/to/file
It can be done in shorter way: git reset path/to/file
>
> The motivation is that I always forget syntax and have to google each
> time I want to undo accidentally added files. Unadd is just much
> easier to remember and quite obvious.

--  Regards, Konstantin

Filipp Bakanov· Oct 28, 2020, 12:21 UTC · re: Konstantin Tokarev · lore

Re: Proposal: "unadd" command / alias.

Thank you, that solves the issue.
On Wed, 28 Oct 2020 at 15:13, Konstantin Tokarev <annulen@yandex.ru> wrote:
Show 23 quoted lines
>
>
>
> 27.10.2020, 23:10, "Filipp Bakanov" <filipp@bakanov.su>:
> > Hi! I suggest to add "unadd" command, that will undo a git add command.
> >
> > git unadd path/to/file
> >
> > It will be an alias to:
> >
> > git reset HEAD -- path/to/file
>
> It can be done in shorter way: git reset path/to/file
>
> >
> > The motivation is that I always forget syntax and have to google each
> > time I want to undo accidentally added files. Unadd is just much
> > easier to remember and quite obvious.
>
>
> --
> Regards,
> Konstantin

← back to recent threads