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

Question about “committed, but not pushed” #2

Closed
simevidas opened this Issue Dec 3, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@simevidas

simevidas commented Dec 3, 2016

May I ask a n00b question about the approach from the section “If your changes are committed, but not pushed”?

It appears that reset deletes the commit(s) and then commit creates a new commit. Would it not be better if the original commit(s) (incl. commit message(s)) could be moved from the wrong to the good branch?

Again, I’m a Git n00b. Sorry if what I’m saying doesn’t make sense.

@toddself

This comment has been minimized.

Show comment
Hide comment
@toddself

toddself Dec 5, 2016

Owner

It does! There are several ways you can do this!

I prefer the back out since it gives me an automatic opportunity to make sure I've actually got all my files that I needed and can re-write the commit message.

You can also create a new branch from the branch you mistakenly committed onto, then remove the commits from that branch

[master]:> git checkout -b my-new-branch
[my-new-branch]:> git checkout master
[master]:> git reset --hard HEAD~1 // or however far you need to go back

What I dislike about this is that you can more easily drop a commit you didn't intend to drop. (It can be found and added back where you need it though).

I should update my stuff to include this!

Thanks for the question

Owner

toddself commented Dec 5, 2016

It does! There are several ways you can do this!

I prefer the back out since it gives me an automatic opportunity to make sure I've actually got all my files that I needed and can re-write the commit message.

You can also create a new branch from the branch you mistakenly committed onto, then remove the commits from that branch

[master]:> git checkout -b my-new-branch
[my-new-branch]:> git checkout master
[master]:> git reset --hard HEAD~1 // or however far you need to go back

What I dislike about this is that you can more easily drop a commit you didn't intend to drop. (It can be found and added back where you need it though).

I should update my stuff to include this!

Thanks for the question

@toddself

This comment has been minimized.

Show comment
Hide comment
@toddself

toddself Dec 5, 2016

Owner

The post has been edited to reflect this other way of removing the commits!

Owner

toddself commented Dec 5, 2016

The post has been edited to reflect this other way of removing the commits!

@toddself toddself closed this Dec 5, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment