Reputation: 2398
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.
Upvotes: 25
Views: 45561
Reputation: 20256
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?
.Upvotes: 48
Reputation: 3043
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!
Upvotes: 6