Skip to content
Steve Stanton edited this page Sep 17, 2019 · 12 revisions

When you add commands to any branch, they are known only to that branch. If you want other branches to know about them, you need to use the merge command (there is no need to commit your changes prior to that).

The merge command provided by altcmd makes it possible to merge commands from a child branch to its parent, and vice versa. You cannot merge with any other branches.

To understand how this works, you can use the recall command to list the recent commands known to a branch. The basic recall command just lists the commands in the current branch:

   work[1]> recall
   [0] = branch work 2

Here we have just the command line that was used to create the branch. You can also list commands that have been inherited or merged from other branches by using the --all option:

   work[1]> recall --all
   /origin/work[0] = branch work 2
   /origin[1] = name Dave
   /origin[0] = ICreateStore

In addition to the command lines, you can also see the path of the branch that the command came from.

Try adding some extra names to the work branch, and see what you get.

   work[1]> name Neil
   work[2]> name Robin
   work[3]> recall --all
   /origin/work[2] = name Robin
   /origin/work[1] = name Neil
   /origin/work[0] = branch work 2
   /origin[1] = name Dave
   /origin[0] = ICreateStore   

Now switch back to the parent branch to see what that shows. You can do that with the 'checkout' command (or if you prefer, the 'cd' command alias does the same thing). When switching to the parent branch, you do not have to type the full name of the parent, entering 'cd ..' will work just as well.

   work[3]> cd ..
   [3]> recall -all
   /origin[1] = name Dave
   /origin[0] = ICreateStore   

Neil and Robin were entered into the child branch but because they have not been merged, they are still unknown to the parent. But before doing that, use the 'branch --list command to list the status of the branches (if you prefer, the 'ls' command alias does the same thing).

   [3] ls
   *  /origin
      /origin/work (ahead of parent by 2)
   
   5 commands in 2 local branches

Notice that the child is apparently ahead of the parent by only 2 commands, but you may recall that the child actually contains 3 commands (the branch command itself, followed by two names). The count shown here only includes commands that will contribute something new to the parent. The branch command itself is discounted because it relates to commands that the parent already knows about.

Now merge the child branch and use the recall command to see what the parent looks like:

   [3] merge work
   [4] recall --all
   /origin/work[2] = name Robin
   /origin/work[1] = name Neil
   /origin/work[0] = branch work 2
   /origin[2] = merge work [0,2]
   /origin[1] = name Dave
   /origin[0] = ICreateStore   
   

The parent branch now knows about the commands that were added via the child branch. Listing the branches will show that both branches are in sync.

   [3] ls
   *  /origin
      /origin/work
   
   6 commands in 2 local branches

The same procedure is used to merge new commands from the parent into the child:

   [3] name Jennifer
   [4] ls
   *  /origin
      /origin/work (behind parent by 1)
	  
   7 commands in 2 local branches
   [4] cd work
   work[3]> merge ..
   work[4]> ls
      /origin
   *  /origin/work
   
   8 commands in 2 local branches   

Whenever you merge, you need to be working in the branch that is to receive the extra commands. So, having entered Jennifer as part of the parent branch, we had to then switch to the child before doing the merge.

Clone this wiki locally