Is there an inversion for Git octopus merge?

Git has the highly advertised ability (?) Octopus-merge, which can combine many goals into one.

But is there something that would be exactly the opposite, to make several simultaneous branches from one node?

Suppose I have a bunch of code for a project, and I just started using Git. Some of the functions are completed in this project, others are not working yet. I would like these incomplete functions to move to their own and separate branches, and the wizard, if possible, become “complete” without incomplete code.

Now I could, of course, do it all in one step: create a branch of the "incomplete function # 1" and delete the files specific to that function from the wizard. Then I will transfer the wizard to the "incomplete function number 2" and again delete the special files # 2 from the wizard, as well as from the first branch. And therefore, the workload is increasing for every broken I do.

Is there anything that could help me in this scenario?

+4
source share
2 answers

Side note: the merging of octopuses and the scenarios of the branching axis of an octopus are very different. Remember that pointers in a DAG (directional acyclic graph) capture a point from a child (newer) to a parent or parents. Therefore, in the case of the merger of octopuses, you have a commit (commit object), which has more than two parents; in the case of an “octopus branch point” you just have a few commits pointing to the same thing as its parent.

octopus merge:

1 <---- M 2 <----/ | 3 <------| 

Octopus branch point:

 P <----- 1 ^-------- 2 ^-------- 3 

So, I think the naming of this question is simply wrong


Answer

Now, if you want to separate modifications in your workspace between different branches in order to put each function in a separate topic branch, you can use an explicit intermediate area (aka index) in Git.

Suppose you have changed two files: “a” and “b,” and you want to change the file “a” to go to branch “A”, and change in the file “b” to go to branch “B”, suppose that the branch you are currently in is the branch point that you want to create at the base of the many branches you want to create, called "master".

First let's create a branch "A"

 $ git checkout -b A master 

Git answers:

 M a M b Switched to a new branch "A" 

"M" means that the files "a" and "b" change relative to the point where you based the branch "A" (branch "master"). (Below, I simply put the git answer below the command line call, and not separately mentioning the answer.)

Add the contents of the file 'a' to the intermediate region (index).

 $ git add a 

Note that if you want to add only a subset of the changes in the 'a' file to the 'A' branch, you can use "git add -interactive" (abbreviated "-i") or "git gui" to make changes to intermediate region and other similar manipulations.

Now we commit the changes to branch "A"

 $ git commit Created commit 35d0061: Commit description... 1 files changed, 1 insertions(+), 0 deletions(-) 

Note that we did not use the -a option for git -commit!

By the way, if you want to test the changes before leaving the staging area, you can use "git stash save --keep-index" to get the workspace in the state that you have to commit using "git commit", check the changes, then go back to the previous state using "git stash pop-index" (or "git stash pop", I don’t remember which one you need here).

Now we create another branch, branch "B", based on the branch "master"

 $ git checkout -b B master M b Switched to a new branch "B" 

You can easily see that the changes that you left for branch "B" (changes that you did not commit to branch "A") relate to the newly created branch "B". No need to delete files or delete changes. You do not need to know what is in other industries. Everything is automatic.
Once again, add the contents of the file 'b' to the intermediate area (index) and commit to branch 'B':

 $ git add B $ git commit 

You can repeat this as often as possible, and it does not get complicated with the new branch.

NTN

+11
source

Since you just started using Git, it would be easier to start again and just pass your "complete" code to the "Master" branch. Then check the new branch from the wizard for the function and commit this "incomplete" function code to your own branch. Repeat for each branch of the function.

In any case, you need to break the code into functions and "complete", so use this to configure your repository.

+1
source

All Articles