Git push-force, backstage

what exactly happens when you git click on --force?

I searched on the Internet for about an hour, and the most important answer I can find is:

Same as [git push], but force the push even if it results in a non-fast-forward merge. Do not use the --force flag unless you're absolutely sure you know what you're doing. 

-source from https://www.atlassian.com/git/tutorial/remote-repositories#!push

I understand this quite well, I think, but for me it seems like git push --force will push. Despite my searches, I cannot find anything specific that describes the process associated with force pushing.

Hypothetically, I have a basic repo setup called git @ heroku.com: my-app.git, and a mirror of this repo configured on Heroku for a production called git @ heroku.com: my- application-staging.git.

I created a local branch named "new_changes", did the job, and clicked on a stage from this branch.

I did not like the results, so I abandoned the project, created a new branch named "more_new_changes", did some work, tested it locally, teamed up with the master and tried to click on the stage, just to make sure the setting is relevant.

My press tells me ...

 Pushing to git@heroku.com :my-app-staging.git Fetching repository, done. To git@heroku.com :my-app-staging.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to ' git@heroku.com :my-app-staging.git' To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes (eg 'git pull') before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details. 

I do not want to combine the code that is in my local branch of the wizard - in fact, I want this intermediate code to disappear. (Obviously, branches would be called hashes, but for an argument), I suppose if my setting looks like

push079 β†’ push080 β†’ new_changes(HEAD)

and my local looks like

push079 β†’ push080 β†’ more_new_changes(HEAD)

and I decided to click on the stage using -force, then the result will be an intermediate branch that looks like

push079 β†’ push080 β†’ more_new_changes(HEAD)

Alternatively, it may look more like

push079 β†’ push080 β†’ new_changes
\
> more_new_changes(HEAD)

but if I am wrong and he just crush them together and I finish something like

push079 β†’ push080 β†’ new_changes β†’ more_new_changes(HEAD)

then I lose the continuity of having an intermediate repo that reflects the mirror of my production repo.

So, what really happens behind the scenes when you click the --force button?

+1
git version-control github
source share
2 answers

It is very simple: the Git client sends a message that is "make such-and-such-and-such-and-such-and-such-and-such-and-such-and-such-and-such-and-such-and-such-and-such-and-such-and-such-and-such-and-such-and-such-and-such-and-such-and-such-and-such-and-such-and-such-and-such-and-such-and-such-and-such-value value". Information about the exchange of the server and the client until the server receives the required commit and its history. Then the server updates ref, i.e. Writes SHA1 to a text file.

What happens in your case is that the server refuses to force click because it does not want to lose the history.

+1
source share

The result of git push --force will actually be:

 push079->push080->more_new_changes(HEAD) \ ->new_changes (reflog only or git fsck) 

One commit will replace another: you don’t need to get rid of the previous commit before pushing a new one.

This answer shows how git fsck will allow you to return a story that you would replace with git push --force .

+1
source share

All Articles