git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: How to force a push to succeed?

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Aug 23, 2017, 16:56 UTC
Message-ID
<20170823165634.GI13924@aiede.mtv.corp.google.com>
In-Reply-To
<CAH8yC8nHnbWTG4hxD+mEHKPS6eWcBb7yMsgN886=aTWaBRhE5A@mail.gmail.com>
Hi Jeffrey,
Jeffrey Walton wrote:
Show 7 quoted lines
> From another testing machine, it looks like the changes have not been
> backed out. The previous operation un-did the ADX gear because it was
> an evolutionary dead-end.
>
> via$ git pull
> From https://github.com/noloader/cryptopp
>  + 66654dd...559fc3b master     -> origin/master  (forced update)
The Git User Manual[1] explains:
| We have already seen how to keep remote-tracking branches up to date
| with git-fetch(1), and how to merge two branches. So you can merge
| in changes from the original repository’s master branch with:
|
| $ git fetch
| $ git merge origin/master
|
| However, the git-pull(1) command provides a way to do this in one step:
|
| $ git pull origin master
There is also some discussion of that in "git help pull".

But that doesn't appear to be what you want to do. You are not looking to incorporate remote changes into your local branch, preserving any changes that are in your local branch --- instead, you are looking to move to what the remote server has, overwriting any changes that are in your local branch.

You can do that with
	git fetch
	git reset --hard origin/master
See also the discussion of --force in "git help push".

I also recommend looking at the Git Tutorial[2]. When it introduces "git reset --hard" to back out changes, it says:

| $ git reset --hard HEAD^ # reset your current branch and working
|                          # directory to its state at HEAD^
|
| Be careful with that last command: in addition to losing any changes
| in the working directory, it will also remove all later commits from
| this branch. If this branch is the only branch containing those
| commits, they will be lost. Also, don’t use git reset on a
| publicly-visible branch that other developers pull from, as it will
| force needless merges on other developers to clean up the history.
| If you need to undo changes that you have pushed, use git revert
| instead.

If you have ideas about how it could explain this better (or even better, how commands could behave to avoid needing such explanation) then I would be happy to hear them.

(Side note: I am starting to wonder whether what you were looking for was something like "git revert", especially if this is a project involving more than one person.)

> You know, I look at how fucked up yet another simple workflow is, and
> all I can do is wonder. It is absolutely amazing. Its like the project
> goes out of its way to make simple tasks difficult.

I understand your frustration, but accusing people of trying to make your life difficult isn't a particularly productive way to get help from them.

For the future, some ways to get good results are
- to describe the background of what you are trying to do
- to describe where you looked for answers, so that we know what
  documentation to improve

The #git IRC channel on freenode can also be helpful for real-time help. But I encourage you to also keep writing here so that we know what documentation and workflows to improve.

Thanks and hope that helps, Jonatha

[1] https://www.kernel.org/pub/software/scm/git/docs/user-manual.html#getting-updates-With-git-pull [2] https://www.kernel.org/pub/software/scm/git/docs/gittutorial.html

Previous: Johannes SixtNext: Kevin Daudt
Message 7 of 8 in “How to force a push to succeed?”
  1. Jeffrey WaltonAug 22, 2017
  2. Stefan BellerAug 22, 2017
  3. Jeffrey WaltonAug 22, 2017
  4. Jeffrey WaltonAug 22, 2017
  5. Jeffrey WaltonAug 22, 2017
  6. Johannes SixtAug 23, 2017
  7. Jonathan NiederAug 23, 2017
  8. Kevin DaudtAug 23, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.