Home git How to roll back to Commit and pour it on a remote...

How to roll back to Commit and pour it on a remote repository?




There are two repository:

  1. naked (bare) repository, all take a copy of it, it has a master branch, which always corresponds to the product code
  2. there is a local repository

Developer roll back to the previous commit in the local repository Git Reset --Soft , then makes commit, then Push.

Push deviates, the developer makes the pool and dares the local master and with remote, after which the canceled codes rows rise again and the meaning of the ventiy is lost!

Tell me, please, how to roll back to commit and pour it on a remote repository?

Answer 1, Authority 100%

For simplicity Suppose that the problem comite is only one.

To roll back Posted by (Push) Commit, there are two main ways:

  1. git revert_number_number_number . Creates a second, “opposite” commote, “with a minus sign.” After his publication, it will be a state, as to a problem commit, but in history there will be a couple of unnecessary-commit + cancellation-unnecessary committees.
  2. Git Push --Force . Before that, you need Git Reset as advised in the comments. This option should be used with caution. Consider the following cases:
    1. No one has yet seen published changes (including “Robots”, which can automatically do something at PUSH). Then - force the best option.
    2. several people have already been updated after an unsuccessful commit. Then, before using - Force , you should notify them, since on their side - force can “draw up” the situation and demand additional actions. If, instead of a problem commit, not to put another other commit, then the problem commit can again get to the server (even without - force ‘a) from these developers.
    3. Someone has already published changes over an unsuccessful commit. Then - Force will raise their new commitments. From this you can protect the - Force-with-Lease option. In this case, you need to upgrade and do git rebase -i , and then - force (and during this operation there may be more new commits). Here Git Revert will be more appropriate.
    4. Many people have already been updated, there are several published or unpublished changes “over” a bad commit: Git Revert .

Answer 2, Authority 67%

as option

Git Reflog – will give a list of head with numbers and description, it is enough to choose the status and make a reset to this head.

Git Reset --hard head @ {number }

Head is a pointer to the current branch, which, in turn,
It is a pointer to the last commit, made in this branch. it
It means that Head will be the parent of the next committed commit. How
The rule is the simplest to count the head with a snapshot of your last commit.

Answer 3

Depending on the platform, you can write like this:


Rollback to 1 Commit locally:

Git Reset --hard head ~ 1

Note: This is a potentially dangerous team , as it
Remits all your unfixed changes.

then delete in the repository remote command:

Git Push Origin -f

By analogy Bitbucket

Rollback to 1 Commit locally:

Git Reset --hard head ~ 1

and remotely delete the command:

Git Push -f Origin Head ^: Master

Note: Instead of the Master branch, you can use any other
branch. This command you are only removed from BitBuckket.

head ~ 1 and head ^ can be interchangeable .

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions