threads / discuss / 46653

How to force a push to succeed?

Subject: How to force a push to succeed?

## tl;dr

8 messages between Aug 22, 2017 and Aug 23, 2017.

replies: 7people: 5as markdown or json

Jeffrey Walton· Aug 22, 2017, 21:55 UTC · lore

I tested some changes that lead to a dead end. The changes need to be removed. The changes were added in 7 commits.

I went back in time to the point before the changes:
    $ git reset --hard HEAD~7
    HEAD is now at 559fc3b Fix benchmark selection code (GH #464)
When I attempted to push:
    $ git push
    Username for 'https://github.com': noloader
    To https://github.com/noloader/cryptopp.git
     ! [rejected]        master -> master (non-fast-forward)
I tried to commit, but Git claims there's nothing to add:
    $ git commit
    On branch master
    Your branch is behind 'origin/master' by 7 commits, and can be
fast-forwarded.

Commit seems to be the wrong command as Git appears to be trying to do something I don't want.

How do I force the push to succeed?
Thanks in advance.
Stefan Beller· Aug 22, 2017, 21:57 UTC · re: Jeffrey Walton · lore

Re: How to force a push to succeed?

On Tue, Aug 22, 2017 at 2:55 PM, Jeffrey Walton <noloader@gmail.com> wrote:
Show 28 quoted lines
> I tested some changes that lead to a dead end. The changes need to be
> removed. The changes were added in 7 commits.
>
> I went back in time to the point before the changes:
>
>     $ git reset --hard HEAD~7
>     HEAD is now at 559fc3b Fix benchmark selection code (GH #464)
>
> When I attempted to push:
>
>     $ git push
>     Username for 'https://github.com': noloader
>     To https://github.com/noloader/cryptopp.git
>      ! [rejected]        master -> master (non-fast-forward)
>
> I tried to commit, but Git claims there's nothing to add:
>
>     $ git commit
>     On branch master
>     Your branch is behind 'origin/master' by 7 commits, and can be
> fast-forwarded.
>
> Commit seems to be the wrong command as Git appears to be trying to do
> something I don't want.
>
> How do I force the push to succeed?
>
> Thanks in advance.
Checkout the --force[-with-lease] argument.
https://git-scm.com/docs/git-push
Jeffrey Walton· Aug 22, 2017, 22:03 UTC · re: Stefan Beller · lore

Re: How to force a push to succeed?

On Tue, Aug 22, 2017 at 5:57 PM, Stefan Beller <sbeller@google.com> wrote:
Show 31 quoted lines
> On Tue, Aug 22, 2017 at 2:55 PM, Jeffrey Walton <noloader@gmail.com> wrote:
>> I tested some changes that lead to a dead end. The changes need to be
>> removed. The changes were added in 7 commits.
>>
>> I went back in time to the point before the changes:
>>
>>     $ git reset --hard HEAD~7
>>     HEAD is now at 559fc3b Fix benchmark selection code (GH #464)
>>
>> When I attempted to push:
>>
>>     $ git push
>>     Username for 'https://github.com': noloader
>>     To https://github.com/noloader/cryptopp.git
>>      ! [rejected]        master -> master (non-fast-forward)
>>
>> I tried to commit, but Git claims there's nothing to add:
>>
>>     $ git commit
>>     On branch master
>>     Your branch is behind 'origin/master' by 7 commits, and can be
>> fast-forwarded.
>>
>> Commit seems to be the wrong command as Git appears to be trying to do
>> something I don't want.
>>
>> How do I force the push to succeed?
>>
>> Thanks in advance.
>
> Checkout the --force[-with-lease] argument.
Perfect, thanks.
Jeff
Jeffrey Walton· Aug 22, 2017, 22:10 UTC · re: Jeffrey Walton · lore

Re: How to force a push to succeed?

On Tue, Aug 22, 2017 at 6:03 PM, Jeffrey Walton <noloader@gmail.com> wrote:
Show 32 quoted lines
> On Tue, Aug 22, 2017 at 5:57 PM, Stefan Beller <sbeller@google.com> wrote:
>> On Tue, Aug 22, 2017 at 2:55 PM, Jeffrey Walton <noloader@gmail.com> wrote:
>>> I tested some changes that lead to a dead end. The changes need to be
>>> removed. The changes were added in 7 commits.
>>>
>>> I went back in time to the point before the changes:
>>>
>>>     $ git reset --hard HEAD~7
>>>     HEAD is now at 559fc3b Fix benchmark selection code (GH #464)
>>>
>>> When I attempted to push:
>>>
>>>     $ git push
>>>     Username for 'https://github.com': noloader
>>>     To https://github.com/noloader/cryptopp.git
>>>      ! [rejected]        master -> master (non-fast-forward)
>>>
>>> I tried to commit, but Git claims there's nothing to add:
>>>
>>>     $ git commit
>>>     On branch master
>>>     Your branch is behind 'origin/master' by 7 commits, and can be
>>> fast-forwarded.
>>>
>>> Commit seems to be the wrong command as Git appears to be trying to do
>>> something I don't want.
>>>
>>> How do I force the push to succeed?
>>>
>>> Thanks in advance.
>>
>> Checkout the --force[-with-lease] argument.
Thanks again Stefan,

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)
Already up-to-date.
via:$ cat integer.cpp | grep ADX
#if defined(CRYPTOPP_ADX_AVAILABLE)
# define CRYPTOPP_INTEGER_ADX 1
#if CRYPTOPP_INTEGER_SSE2 || CRYPTOPP_INTEGER_ADX
#if CRYPTOPP_INTEGER_ADX
extern int CRYPTOPP_FASTCALL ADX_Add(size_t N, word *C, const word *A,
const word *B);
#if CRYPTOPP_INTEGER_ADX
        if (HasADX())
                s_pAdd = &ADX_Add;
#if CRYPTOPP_INTEGER_SSE2 || CRYPTOPP_INTEGER_ADX

Above, there should be no references to ADX. Looking at the GitHub the changes have been applied.

Any ideas?
Jeff
Jeffrey Walton· Aug 22, 2017, 22:26 UTC · re: Jeffrey Walton · lore

Re: How to force a push to succeed?

Show 35 quoted lines
>>>> Commit seems to be the wrong command as Git appears to be trying to do
>>>> something I don't want.
>>>>
>>>> How do I force the push to succeed?
>>>>
>>>> Thanks in advance.
>>>
>>> Checkout the --force[-with-lease] argument.
>
> Thanks again Stefan,
>
> 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)
> Already up-to-date.
> via:$ cat integer.cpp | grep ADX
> #if defined(CRYPTOPP_ADX_AVAILABLE)
> # define CRYPTOPP_INTEGER_ADX 1
> #if CRYPTOPP_INTEGER_SSE2 || CRYPTOPP_INTEGER_ADX
> #if CRYPTOPP_INTEGER_ADX
> extern int CRYPTOPP_FASTCALL ADX_Add(size_t N, word *C, const word *A,
> const word *B);
> #if CRYPTOPP_INTEGER_ADX
>         if (HasADX())
>                 s_pAdd = &ADX_Add;
> #if CRYPTOPP_INTEGER_SSE2 || CRYPTOPP_INTEGER_ADX
>
> Above, there should be no references to ADX. Looking at the GitHub the
> changes have been applied.
>
> Any ideas?

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.

Johannes Sixt· Aug 23, 2017, 17:06 UTC · re: Jeffrey Walton · lore

Re: How to force a push to succeed?

Am 23.08.2017 um 00:26 schrieb Jeffrey Walton:
> 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.

No, no. So simple your task might look, in the end you have LOST DATA! It is a design goal of Git to make it difficult to lose data.

-- Hannes
Jonathan Nieder· Aug 23, 2017, 16:56 UTC · re: Jeffrey Walton · lore

Re: How to force a push to succeed?

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

Kevin Daudt· Aug 23, 2017, 08:03 UTC · re: Jeffrey Walton · lore

Re: How to force a push to succeed?

On Tue, Aug 22, 2017 at 05:55:25PM -0400, Jeffrey Walton wrote:
Show 28 quoted lines
> I tested some changes that lead to a dead end. The changes need to be
> removed. The changes were added in 7 commits.
> 
> I went back in time to the point before the changes:
> 
>     $ git reset --hard HEAD~7
>     HEAD is now at 559fc3b Fix benchmark selection code (GH #464)
> 
> When I attempted to push:
> 
>     $ git push
>     Username for 'https://github.com': noloader
>     To https://github.com/noloader/cryptopp.git
>      ! [rejected]        master -> master (non-fast-forward)
> 
> I tried to commit, but Git claims there's nothing to add:
> 
>     $ git commit
>     On branch master
>     Your branch is behind 'origin/master' by 7 commits, and can be
> fast-forwarded.
> 
> Commit seems to be the wrong command as Git appears to be trying to do
> something I don't want.
> 
> How do I force the push to succeed?
> 
> Thanks in advance.
By actually doing a force push:
    git push --force-with-lease origin master

But note that this can interfere with others working on the same repository, so be carefull when you use a force push.

Additionally, I can recommend using separate branches for things that might turn up as dead ends (or even for every development). That way, you can just throw away the branch if you want to discard it.

Hope this helps, Kevin.

← back to recent threads