I actually once pushed with --force to git. Git repository and got scolded by Linus BIG TIME It will create a lot of problems for other people. A simple answer is "don't do it I see others gave the recipe for doing so anyway, so I won't repeat them here, but here is a tip to recover from the situation after you have pushed out the amended commit with --force (or +master) First, you find the old commit that you amended (call it OLD, and we'll call the new commit you created by amending NEW) Then create a merge between OLD and NEW, recording the tree of NEW, like "git checkout NEW && git merge -s ours OLD Merge that to your master with "git merge master Update your master with the result with "git push .
HEAD:master Then push the result out Then people who were unfortunate enough to have based their work on the commit you obliterated by amending and forcing a push (which is your being a very very bad boy ) will see the resulting merge will see that you favor NEW over OLD. Their later merges will not see the conflicts between OLD and NEW that resulted from your amending and they do not have to suffer.
I actually once pushed with --force to git. Git repository and got scolded by Linus BIG TIME. It will create a lot of problems for other people.
A simple answer is "don't do it". I see others gave the recipe for doing so anyway, so I won't repeat them here, but here is a tip to recover from the situation after you have pushed out the amended commit with --force (or +master). First, you find the old commit that you amended (call it OLD, and we'll call the new commit you created by amending NEW).
Then create a merge between OLD and NEW, recording the tree of NEW, like "git checkout NEW && git merge -s ours OLD". Merge that to your master with "git merge master" Update your master with the result with "git push . HEAD:master" Then push the result out.
Then people who were unfortunate enough to have based their work on the commit you obliterated by amending and forcing a push (which is your being a very very bad boy) will see the resulting merge will see that you favor NEW over OLD. Their later merges will not see the conflicts between OLD and NEW that resulted from your amending and they do not have to suffer.
3 I'm very well aware what happens when you force push an amended commit (by destroying history). Luckily enough, I was the only developer on the project with the remote repo being on a network drive so it wasn't that big of a deal. I never thought about merging an amend commit, so I'll upvote this.
– Spoike Jan 11 '09 at 12:06 11 What did Linus say? – Alan Apr 6 at 17:50.
Short answer: Don't push amended commits to a public repo. Long answer: A few Git commands, like git commit --amend and git rebase, actually rewrite the history graph. This is fine as long as you haven't published your changes, but once you do, you really shouldn't be mucking around with the history, because if someone already got your changes, then when they try to pull again, it might fail.
Instead of amending a commit, you should just make a new commit with the changes. However, if you really, really want to push an amended commit, you can do so like this: $ git push origin +master:master The leading + sign will force the push to occur, even if it doesn't result in a "fast-forward" commit. (A fast-forward commit occurs when the changes you are pushing are a direct descendant of the changes already in the public repo.).
Quick rant: The fact that no-one has posted the simple answer here demonstrates the desperate user-hostility exhibited by the Git CLI. Anyway, the "obvious" way to do this, assuming you haven't tried to force the push, is to pull first. This pulls the change that you ammended (and so no longer have) so that you have it again.
Once you have resolved any conflicts, you can push again.
Yes, I wrote about this, see stackoverflow. Com/questions/253055/… ;) – Spoike Sep 22 '09 at 10:58 Thanks that was very helpful. – faB Mar 6 '10 at 23:18.
What you are seeing is a git safety feature. Git refuses to update the remote branch with your branch because your branch's head commit is not a direct descendent of the current head commit of the branch that you are pushing to. If this were not the case, then two people pushing to the same repository at about the same time would not know that there was a new commit coming in at the same time and whoever pushed last would lose the work of the previous pusher without either of them realising this.
If you know that you are the only person pushing and you want to push an amended commit or push a commit that winds back the branch, you can 'force' git to update the remote branch by using the -f switch. Git push -f origin master Even this may not work as git allows remote repositories to refuse non-fastforward pushes at the far end by using the config variable 'receive. Denynonfastforwards'.
If this is the case the rejection reason will look like this (note the 'remote rejected' part):! Remote rejected master -> master (non-fast forward) To get around this, you either need to change the remote repository's config or as a dirty hack you can delete and recreate the branch thus: git push origin :master git push origin master In general the last parameter to git push uses the format :, where local_ref is the name of the branch on the local repository and remote_ref is the name of the branch on the remote repository. This command pair uses two shorthands.
:master has a null local_ref which means push a null branch to the remote side master, i.e. Delete the remote branch. A branch name with no : means push the local branch with the given name to the remote branch with the same name.
Master in this situation is short for master:master.
1 saved the day, thanks – Eelco Jun 10 '10 at 9:30 this did not work with github, it gave me the following message: remote rejected master (deletion of current branch prohibited) – vedang Nov 12 '10 at 13:12 I didn't want to force push (which I knew would solve the issue), but now I guess I have no choice. – vedang Nov 12 '10 at 13:14 1 This is the only solution that worked for my repo hosted with assembla. – Failpunk Feb 4 at 0:56.
I had to fix this problem with pulling from the remote repo and deal with the merge conflicts that arose, commit and then push. But I feel like there is a better way.
Not really. The issue might be that you haven't updated your local copy from the remote repo. Git won't push to it because you may have to deal with merges manually.In my other reply, I have a command (and explanation) that will force a push -- but beware that is may delete changes in the remote.
– mipadi Oct 31 '08 at 18:14.
I usually only have to do this when I have to clean up from committing something that I never should have (a secure file or large binary that I missed/forgot about with . Gitignore) then I need to push that out to the central repo, but I too, feel like there should be a better way. I would say never ever ever do this for a normal code change.
What you are seeing is a git safety feature. Git refuses to update the remote branch with your branch because your branch's head commit is not a direct descendent of the current head commit of the branch that you are pushing to. If this were not the case, then two people pushing to the same repository at about the same time would not know that there was a new commit coming in at the same time and whoever pushed last would lose the work of the previous pusher without either of them realising this.
If you know that you are the only person pushing and you want to push an amended commit or push a commit that winds back the branch, you can 'force' git to update the remote branch by using the -f switch. Even this may not work as git allows remote repositories to refuse non-fastforward pushes at the far end by using the config variable 'receive. In general the last parameter to git push uses the format :, where local_ref is the name of the branch on the local repository and remote_ref is the name of the branch on the remote repository.
This command pair uses two shorthands. :master has a null local_ref which means push a null branch to the remote side master, i.e. Delete the remote branch.
A branch name with no : means push the local branch with the given name to the remote branch with the same name. Master in this situation is short for master:master.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.