How do I remove commits, waiting to be pushed to remote?
My situation is, that those queued commits (changes) been already pushed (more bellow) and now the server refuses to accept those as they are behind the HEAD.
I tried resetting to another commit, but when I go back to HEAD, pushes reappear again.
Clicking Repository > Refresh Remote Status won't help, it actually added the 2nd waiting push :)
PS: I apologize for my terminology, I'm quite new to git.
.
Update 1
Problems started when I were commiting feature2 to master branch. I don't have rights to commit there so it got stuck. Then I commited again to my personal branch, which was OK. Then I got one waiting commit, never to be pushed, even if I select the right (personal) branch when I click Push.
To remove the commit without changing any source code, you need to perform a "mixed" reset. Right click on the last "good" commit (this will probably be origin/master ). Select "Reset current branch to this commit." In the resulting dialog, select "Mixed..." from the drop down and click OK.
When you push a commit, the safest way to revert it (rather than forcing the push with -f) is to use the revert function, so a new commit is created on top of your previous commit. This is possible to do using Sourcetree, right clicking in the commit that you want to revert, and selecting "Reverse commit...".
On SourceTree for Windows, right click the files you want to discard (in the Working Copy Changes list), and choose Discard. On git, you'd simply do: git reset --hard to discard changes made to versioned files; git clean -xdf to erase new (untracked) files, including ignored ones (the x option).
Git commits form a commit graph. Branches are just named pointers to commits in that graph.
Given that, your question can be restated as
My local master branch is pointing to a different commit than the remote master branch. How do I make my local master branch point to the same commit as the remote master branch?
There are two ways to accomplish this. Move the remote branch (git push
) or move the local branch (git reset
). As you said, you can't push to the remote master branch, so options 1 is off the table, that leaves option 2.
Note that the reset
operates on the currently checkout branch1 so you'll first want to make sure you are currently on the master branch and then move that branch to the same commit as the remote master branch.
git checkout master <--- make sure you're on the master branch git reset --hard origin/master <--- put your master branch on the same commit as origin/master
Now that master and origin/master are on the same commit, there should be no commits to push.
reset
operates on the current HEAD, but for the sake of this explanation it's easier to think of of it as operating on branches. For more information see this question: What is HEAD in Git? .Have you tried by doing: git reset --hard HEAD~1
? In this way, you will have the head again on your local repo. Otherwise, I've seen a funny page that might be useful: http://ibrokegit.com/
Most of the times, this things should be solved by using the command line, instead of the GUI (in this case, SourceTree).
Hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With