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!
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.
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!
The work is in full swing and there is only one thing left - to stink the master with these branches.
? 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
:
.
master
.
, , , (git push
) git
, , .
git, , . , , ?