Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add discard and discard-all aliases #27

Merged
merged 1 commit into from
May 23, 2017
Merged

Add discard and discard-all aliases #27

merged 1 commit into from
May 23, 2017

Conversation

pachoyan
Copy link
Contributor

@pachoyan pachoyan commented May 22, 2017

Add discard and discard-all aliases:

Usages:

Discards files

 git discard file-name
  • Parameter would be the file name or pattern to discard

Discards working directory

  git discard-all
  • Discards all the working directory.

Why discard?

It is an action which is used in several git GUIs, for example Source Tree.

@phdru
Copy link
Contributor

phdru commented May 22, 2017

discard-all seems to be equivalent to reset --hard HEAD, right? See existing alias reset-to-pristine.

May I ask you to describe it a bit better? Something like
# Discard uncommitted changes in a (list of) file(s)

@pachoyan
Copy link
Contributor Author

pachoyan commented May 22, 2017

Of course!, I'll change the description to # Discard uncommitted changes in a (list of) file(s) .


On the other hand, discard-all is not equivalent to reset --hard HEAD, not at all. discard-all discards updates and untracked files from working tree, otherwise reset --hard HEAD discards changes from both: stage area (index) and working tree.

Let me explain it:
Sometimes, IMO is useful is to add some file(s) to your stage area (index) and discard the others.
For example, if you are working in something and it is finished (prepared to commit), then you have an idea but you are not sure if it is good or not, so you can add your changes to the stage area, prove your idea and if it is not a good just discard working tree changes, and commit the prepared (changes in stage area).


Should I rename it?

@phdru
Copy link
Contributor

phdru commented May 22, 2017

Ok, go on. I recommend to amend your commit and force-push it to avoid cluttering git logs.

@joelparkerhenderson
Copy link
Member

joelparkerhenderson commented May 22, 2017

Good idea, thanks!

What's your opinion of the concept of discard? Should it do a clean or not?

I would expect something like this:

discard = checkout --
discard-all = checkout -- . 

Or something like this:

discard = !git clean -df && git checkout --
discard-all = !git clean -dffx && git checkout -- :/ 

I would not expect one alias to do clean, and the other to not do clean.

Maybe there's a word that's more semantic than "all" to mean your intent of "plus do a clean before"?

@pachoyan
Copy link
Contributor Author

pachoyan commented May 22, 2017

@joelparkerhenderson you made me think about that, and you're right, it should be two different concepts. Until now, my concept of discard-all was clean the working tree, but actually, it should be clean.

On the one hand, we could have two aliases to discard the changes of tracked files in the working tree (one for specific files, and other for all files) (index or stage area is not discarded). They would the discard aliases:

discard = checkout --
discard-changes = checkout -- .

On the other hand, we could have the clean aliases, which cleans the working tree: untracked and updated files (index or stage area is not cleaned).

I propose these:

 clean-file <file name>
 clean-working-tree

What do you think? Which names do you propose?

@joelparkerhenderson
Copy link
Member

I like this one:

discard = checkout --

I like it because it's semantic, and user friendly, and easy to use with a variety of paths such as:

discard example.txt
discard .
discard :/ 

For the clean concept, how about the word "cleanout"? Because it's a hybrid of "clean" and "checkout".

cleanout = !git clean -df . && git checkout -- .

Could it help to have paths? For example something like this:

cleanout = !"f() { paths=${@:-.}; git clean -df \"$paths\"; git checkout -- \"$paths\"}; f"

@pachoyan
Copy link
Contributor Author

pachoyan commented May 23, 2017

I've added the discard alias (I also like it):

discard = checkout --

Also the cleanout (I like this name) but I decided to not have paths. Just apply the clean-out in the working tree.
So, the alias is like next:

cleanout = !git clean -df && git checkout -- .

It cleans the working tree and also discards the changes.

@joelparkerhenderson
Copy link
Member

Excellent. Thank you so much for your work and your discussion!

@joelparkerhenderson joelparkerhenderson merged commit 8f504f9 into GitAlias:master May 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants