I went through a similar problem and the solution that I will pass on now has served me perfectly. I’ll do it as a thorough step-by-step to also help other people who at least have the basics of git, which is to create, delete, update, and switch branch’s, "commit" and others.
At first I created a new branch not to apply commands that may prevent the use of branch in the future.
- First update the master, then update your
*branch*-antiga
from the master and also from the master create a *branch*-nova
. The aim will be to apply commit for commit of *branch*-antiga
in *branch*-nova
;
In the *branch*-antiga
use the command: git log --author="Fulano da Silva" --name-only
. What does this command do? The git-log shows confirmation logs and parameters --author=<pattern>
applies a "Pattern" in the header of commit. In that case you’ll get the commit’s by name and --name-only
shows the "path/names" of the changed files. Here is an example of the output of the complete code in the terminal:
commit 94d580b6c9480ac23908799681bebc947a3e760f
Author: Djalma Manfrin <[email protected]>
Date: Fri Jan 6 11:12:03 2017 -0200
nome do commit
caminho/do/arquivo/arquivo_1.php
caminho/do/arquivo/arquivo_2.php
caminho/do/arquivo/arquivo_3.php
Note: Notice that the commit are in order. From the latest to the oldest. This order is important for the next step. We will apply commit for commit from the oldest to the newest.
- To make it easier, divide the terminal screen into two screens. On a screen run the command of step 2 to list the commit’s and the other, switch to the
*branch*-nova
and apply the command: git cherry-pick 68e4bde4a83910cb0b4a8df82078e70131ce9280
. What does this command do? The git-Cherry-pick applies the amendments in branch current of a commit existing. Amend the hash as explained in step 2, from the oldest to the newest.
Note: Usually when executing the command git cherry-pick
does not generate conflict, but if it does, you will have to solve in the arm analyzing the code you want "commit". Each conflict is a particular case and if it happens comment or open a new question on Stack so that we can help you. In case it is not necessary to touch the commit, Jump to step 5
- As I had informed in the question and as was also my case. In a single commit there were low and large impact changes to the system as a whole. So in that case I had to apply the command:
git reset HEAD^1
. What does this command do? The git-reset reboots the HEAD current for the specified state passed as parameters. In our case the specified state will be HEAD^1
.
Note: In general, the command git-reset
is the opposite of git add
. Our specification HEAD^1
means that we want to change/return the HEAD one commit back. This commit is not lost. It goes back as changes that can be "commited". This will allow to revert the changes one commit and "commit it in parts". In our case, it will be possible to separate by commit the complexity in low and large. Finally, commit changes as required by.
- After finishing the current commit, back to step 3. This is the way I found to solve my problem. I hope it helps you.