Error: failed to push some refs to... and subsequent Amend

Source: Internet
Author: User
Tags using git

Today, I encountered a problem when using git. The following error occurs when you want to push a remote Branch:

! [Remote Rejected] Master-> refs/For/Master (Change 144 closed)

Error: failed to push some refs...

Check that the version of the local branch is lower than that of the remote branch.

The solution involves the following problems:

1. (not recommended) The current branch is pull directly. A conflict is found during merge. After resolution, a commit-amend error occurs, to the effect that "amend cannot be used in merge ".

2. A new branch is created to save the current job. Go back to the master branch and run the GIT reset -- hard *** (*** is the first four digits of commit_id) command to roll back to the previous commit status, make sure that the commit node is on the remote branch instead of the local unpushed commit node. Then, pull can smoothly update the local master branch to be consistent with the remote branch. Then merge the new branch to the master branch, and then return to the case of 1. After the merge, the Amend cannot be created.

(The method 2 is used because a backup is created, which can be easily recovered if problems occur during merging .)


An error is reported for amend in the above two methods, but the merge can be completed successfully if a new commit is created.

In fact, if there is no conflict in the merge process, a new commit will be automatically created. The description automatically added is merge branch '...'. However, if a conflict occurs, it will stop. After we resolve the conflict ourselves, manually add-> commit to create a node. This is the default description or merge branch '...'.


The reason why I keep trying Amend is because of work needs. However, there is no good solution yet. According to the principle of merging, it should be impossible to go to amend.

However, git provides another method: To combine rebase.

In the new branch, git rebase master can be used for derivation. After the derivation, The commit under the new branch appears at the lowest end of the master branch, in this way, the changeid of the push commit will not change.

The above derivation is based on the absence of conflicts, and the case of conflicts remains to be tested.


Error: failed to push some refs to... and subsequent Amend

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.