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 a new rule, how to discard specific unstaged changes #103

Merged
merged 1 commit into from
Dec 29, 2016

Conversation

codeofcarson
Copy link

I ran into a problem where I wanted to get rid of some hunks in my changes but wasn't ready to commit, and I wasn't having an easy time doing it because some of the hunks were in files where I had made changes I wanted to keep.

I could discard all changes to a file with git checkout but needed a way to sift out the good ones and keep them in my working copy.

Stash ended up being the best tool since you can stash -p and stash only specific hunks.

@codeofcarson
Copy link
Author

If I was required to open an issue first I can do that, please let me know. I am very new to contributing to non-work projects.

Thanks

@RichardLitt
Copy link
Collaborator

You're good, @codeofcarson, this was the right way to do this! Thank you. As it happened, I ran across this issue today, and didn't think of resetting sections this way. Good thinking!

Might be good to mention that what you're doing with stash followed by reset --hard - effectively, you're suggesting that I save snippets I want in stash, and then hard reset everything else. There's another strategy, too:

git stash -p 
# Select all of the snippets you don't want to save
git stash drop

This will delete all of the snippets in the latest stash, while keeping old stashes and not effecting lines you don't add to the stash. Perhaps you should mention this strategy, too? And add a # Select all of the snippets you want to save in between stash -p and git reset --hard in your example.

How does that sound?

@RichardLitt
Copy link
Collaborator

I see this is your first PR - Well done! ⭐️ You're awesome. In case you don't know, to add the changes I suggested, just add another commit on top of this, or amend your commit and force push to this branch.

@codeofcarson
Copy link
Author

Thanks!

I was slightly nervous about it but I'm glad I got it mostly correct.

I have made the changes you have described and force pushed an amended version of the commit.

This should incorporate all of your suggestions which, in my opinion, improve the quality of my commit.

$ git stash -p
# Select all of the snippets you don't want to save
git stash drop

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs closing ```.


When you want to get rid of some, but not all changes in your working copy

First strategy, stash all good changes, reset working copy, reapply good changes
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a period at the end :)

<a href="i-want-to-discard-specific-unstaged-changes"></a>
### I want to discard specific unstaged changes

When you want to get rid of some, but not all changes in your working copy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a period at the end.

$ git stash pop
```

Alternate Strategy, stash undesired changes, drop stash
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uncapitalize 'Strategy'

Copy link
Collaborator

@RichardLitt RichardLitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good! Almost done; just some style changes now.

@codeofcarson
Copy link
Author

Fixed.

@RichardLitt RichardLitt merged commit bad1b36 into k88hudson:master Dec 29, 2016
@RichardLitt
Copy link
Collaborator

Awesome! Thank you! <3 🌴

@codeofcarson
Copy link
Author

Happy to help. Great experience, would PR again 10/10.

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.

2 participants