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