Record a code rollback git reset

Keywords: git html5 GitLab Mac

background

  • Code commit and push to the remote warehouse, found that this submission of redundant files, such as no need for simple conflict-prone configuration files.
  • Hope the remote code revokes this commit locally unchanged
  • Re commit code

    operation

  • First git log to view commit history
    Such as:

  • Now we need to cancel the three commits (f8e79f08731a1551c42cabfdedea820a6f01f68b) that contain the revised articles and return them to the previous submission of 6fb15caa0c498478e02eddb150c339598cbfb2.

    Execute the reset command

    git reset 6fb15caa0c49840978e02eddb150c339598cbfb2

    At this point, it is suggested that:



    It means that everything in your previous commit has been reset.

  • Then add the file you need to submit from the new add and commit it it

    git commit -m "New articles"

    Impulse remote branch

    git pull origin master

    Many people will feel relieved at this time, thinking that it is so successful, but check one before success. You will find that you can't push.

    To git@192.168.1.100:zjc/HTML5.git
    ! [rejected]        master -> master (non-fast-forward)
    error: failed to push some refs to 'git@192.168.1.1000:zjc/HTML5.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.

    It is obvious that pull-pull is not a good way to pull-pull. If pull-pull can pull down the wrong information from push, it will go back to the pre-revolution period.

  • At this time, we need to push it to the remote branch, so we can enforce fame and fortune. So we can knock out the next line of code with confidence.
    git push -f origin master
    Then:
    Counting objects: 53, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (53/53), done.
    Writing objects: 100% (53/53), 1.15 MiB | 0 bytes/s, done.
    Total 53 (delta 27), reused 0 (delta 0)
    remote: GitLab: You are not allowed to force push code to a protected branch on this project.
    To git@192.168.1.100:zjc/HTML5.git
    ! [remote rejected] master -> master (pre-receive hook declined)
    error: failed to push some refs to 'git@192.168.2.100:zjc/HTML5.git'
    Mac-mini:HTML5 wanggeng$ git push -f origin master
    Counting objects: 53, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (53/53), done.
    Writing objects: 100% (53/53), 1.15 MiB | 0 bytes/s, done.
    Total 53 (delta 27), reused 0 (delta 0)
    remote: GitLab: You are not allowed to force push code to a protected branch on this project.
    To git@192.168.1.100:zjc/HTML5.git
    ! [remote rejected] master -> master (pre-receive hook declined)
    error: failed to push some refs to 'git@192.168.1.100:zjc/HTML5.git'
    At first you really think it's a success. Then you'll find an error. Yes, you're right, there's an error. Once again you failed, it seems there's no way to go. Guest Officer, don't worry. When we look at the error message carefully, there's always something we can do. We can see a reminder: remote: GitLab: You are not allowed to push code to a protected branch this. S project.

Processing Protected Branches

  • If the current branch is the protected branch of protected, the git server will refuse to force push. The error is as follows:

    remote: GitLab: You are not allowed to force push code to a protected branch on this project.

    At this point, the rotected attribute of the current branch needs to be temporarily removed.

  • For gitlab, you can enter the "Protected branches" item in the current warehouse settings, temporarily remove the current branch's protected, wait for this push to complete, and reset back to protected.

    View local and server records

    Execution after removal of protection

    git push -f
    Counting objects: 53, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (53/53), done.
    Writing objects: 100% (53/53), 1.15 MiB | 0 bytes/s, done.
    Total 53 (delta 27), reused 0 (delta 0)
    To git@192.168.1.100:zjc/HTML5.git
    + a12aab9...0c95a9f master -> master (forced update)

    It can be seen that the submission has been successful.

    • View local and remote records:


Local submission records are indeed clean, leaving only one modified submission record. This is when the remote warehouse is opened and no previous error submission information is found.

That's the end!

Posted by Goins on Sat, 18 May 2019 15:37:09 -0700