For the method of modifying git commit information, please refer to: git commit – amend modify commit information
Sometimes, after git push, it is found that there are still some small code changes that need to be made. In principle, these changes should not be considered as a new submission.
At this time, we need to cancel the GIT push and git commit, modify the code, and then submit and push again.
In order to achieve this goal, three steps are needed.
1. Cancel the submission
First of all, view the submission information through git log to get the version number you need to go back to
$ git log commit a44822002522f2ab1e3a5e2a1cec00a7d3d02185 (HEAD -> master, origin/master, origin/HEAD) Author: hanchao5272 <[email protected]> Date: Sun Mar 4 11:14:55 2018 +0800 CSDN java reflection 06 member variable field code optimization
commit aa909cff2239536df14820fe086d96305b24e9f1 Author: hanchao5272 <[email protected]> Date: Sat Mar 3 23:43:03 2018 +0800 CSDN java reflection modifier code optimization
We need to cancel this submission of CSDN java reflection 06 member variable field code optimization, so the version we need to go back to is CSDN java reflection modifier code optimization, that is, the version number we need to go back to is aa909cff2239536df14820fe086d96305b24e9f1.
Then, through git reset – soft < version number > reset to the specified version of the submission, to achieve the purpose of canceling the submission
$ git reset –soft aa909cff2239536df14820fe086d96305b24e9f1
The parameter soft means to keep the current workspace for re submission
You can also select the parameter hard, which will undo the modification of the corresponding workspace. You must use it carefully
Then, confirm whether the revocation is successful through git log
$ git log commit aa909cff2239536df14820fe086d96305b24e9f1 (HEAD -> master) Author: hanchao5272 <[email protected]> Date: Sat Mar 3 23:43:03 2018 +0800 CSDN java reflection modifier code optimization
It has been successfully withdrawn.
To achieve the purpose of revoking the version number, GIT push origin master – force is used to force the submission of the current version number
$ git push origin master --force Total 0 (delta 0), reused 0 (delta 0) To github.com:hanchao5272/myreflect.git + a448220...aa909cf master -> master (forced update)
The parameter force must be added to force submission, otherwise the submission will fail and an error will be reported
$ git push origin master To github.com:hanchao5272/myreflect.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to '[email protected]:hanchao5272/myreflect.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Error reason: the local project version number is lower than the remote warehouse version number.
3. Modify the code, re submit and push
//Modify code, add modification git add . //Re submit Git commit - M "CSDN java reflection 06 member variable field code optimization" //Push again git push origin master
The above git revocation has been pushed (push) to the remote warehouse (COMMIT) information operation is the whole content that Xiaobian shares with you. I hope it can give you a reference, and I hope you can support developer more.