Not only newbie developers, but also ardent professionals have to resort to undoing any changes. And then, the first thing that comes to mind is the command git revert
, as the safest way. And there are pitfalls that I want to tell you about.
Let's take a simple situation: a developer decides to implement math functions. But halfway through, he realizes that it would be good to decompose this task, say, into two sub-tasks:
- Implement arithmetic operations (addition, subtraction, division, etc.)
- Implement numeric operations (maximum value, minimum value, modulus of a number, etc.)
It will be easier to check and test. But he has already begun to implement it, the commits have already been created, and what to do? Do not rewrite the same!
![](https://habrastorage.org/webt/zs/xt/4l/zsxt4lraxqnhrbedbt2z6punkim.png)
Consider a commit tree. We see that our developer has created a branch functions
, the Arithmetic class , which is responsible for the implementation of arithmetic operations (commit A ), and the Numerical class , which is responsible for the implementation of numeric operations (commit N ). In total, there are two classes and two commits.
![](https://habrastorage.org/webt/0d/ry/_a/0dry_amwieh3o7lfx824w_nrz60.png)
git revert
It was decided not to rewrite anything, inherit from functions
and create two branches numerical
and arithmetic
. And undo unnecessary commits accordingly. That is, execute git revert N
in the arithmetic branch and git revert A
in the numerical branch. Ingenious and simple!
![](https://habrastorage.org/webt/pb/y5/vj/pby5vjwtlvdbr9v2sis2oq4am4k.png)
The work is in full swing and there is only one thing left - to stink the master with these branches.
![](https://habrastorage.org/webt/zx/fn/8f/zxfn8fvvco3yoxic_ipdsc5usa8.png)
? Arithmetic, Numerical!
, git revert
. 4 :
A βΆ N βΆ revert A βΆ revert N
revert
.
git reset
, reset
, revert
. β¦ . , .
git rebase
β git rebase
.
numerical
arithmetic
git rebase -i βroot
, pick drop. . numerical
:
![](https://habrastorage.org/webt/_l/1q/ai/_l1qai4_5kh-jgxrqc4smm4ibnw.png)
.
master
.
![](https://habrastorage.org/webt/1k/8o/ah/1k8oahpnenouodtuvjfrw7wjsqm.png)
, , , (git push
) git
, , .
git, , . , , ?