miércoles, 9 de diciembre de 2020

GIT Demystifying part 15, Cherry-pick 🍒👌

GIT Demystifying part 15, Cherry-pick 🍒👌


 With cherry pick, git can bring the data of a determined commit. On this simple sample, is shown a tree with a master branch and a branch where features are developed and added on each commit, this is a branch where the data of an specific commit will be extracted to be merged with the master, but only a specific feature, not necesarily the cumulative features of the branch. 

Create the example Tree





Do the cherry-pick 🍒👌, the intention is take the feature-ab and only this feature from the branch-cherry-pick, to be integrated to the master branch.

In this case this feature ab is represented as file2:a and file2:b.

The conflict is solved and then commited. this finish the cherry-picking. So now the master branch has the feature-ab bringed from the cherry-pick branch. and the tree don´t register the join under branches only by the default message of the cherry-pick commit.

This strategy of integrate this specific feature into the master is only to illustrate the posibility of take an specific feature from a list of them into the current master. 

  To perform a better strategy about the develop of software products with diferent versions and limits of each version, is importan maintain the master branch as clean as posible of features, and only add features to master that are strictilly necesary for the product, and work on branches according to the each specific features.

note: In this article Why not use it say that is not recomendable to use it, basically by lost of traceability under determined circunstances.


Let´s do a more complex scenario trying to find diferences between git merge vs git cherry-pick.


command line procedure

$ git init
Initialized empty Git repository in C:/Users/bext/Documents/workspaceSTS448/gitLab01/.git/
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ vi file1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git add f*
warning: LF will be replaced by CRLF in file1.
The file will have its original line endings in your working directory
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git commit --help
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git commit -m "c1"
[master (root-commit) eb0c0fc] c1
 1 file changed, 2 insertions(+)
 create mode 100644 file1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ logg
* eb0c0fc (HEAD -> master) c1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ vi file1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ vi file2
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git add f*
warning: LF will be replaced by CRLF in file1.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in file2.
The file will have its original line endings in your working directory
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git commit -am "c2"
[master 61bc9c4] c2
 2 files changed, 3 insertions(+), 1 deletion(-)
 create mode 100644 file2
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ logg
* 61bc9c4 (HEAD -> master) c2
* eb0c0fc c1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git branch air
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git checkout air
Switched to branch 'air'
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (air)
$ vi file2
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (air)
$ vi file1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (air)
$ git add f*
warning: LF will be replaced by CRLF in file1.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in file2.
The file will have its original line endings in your working directory
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (air)
$ git commit -m "air"
[air adba99a] air
 2 files changed, 2 insertions(+)
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (air)
$ logg
* adba99a (HEAD -> air) air
* 61bc9c4 (master) c2
* eb0c0fc c1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (air)
$ git checkout master
Switched to branch 'master'
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git branch water
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git branch fire
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git branch ground
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git checkout water
Switched to branch 'water'
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (water)
$ logg
* adba99a (air) air
* 61bc9c4 (HEAD -> water, master, ground, fire) c2
* eb0c0fc c1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (water)
$ vi file2
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (water)
$ vi file1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (water)
$ git add f*
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (water)
$ git commit -m "water"
[water 492e5ce] water
 2 files changed, 2 insertions(+)
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (water)
$ logg
* 492e5ce (HEAD -> water) water
| * adba99a (air) air
|/
* 61bc9c4 (master, ground, fire) c2
* eb0c0fc c1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (water)
$ git checkout ground
Switched to branch 'ground'
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground)
$ vi file2
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground)
$ vi file1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground)
$ git add f*
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground)
$ git commit -m "ground"
[ground 3e88a2c] ground
 2 files changed, 2 insertions(+)
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground)
$ logg
* 3e88a2c (HEAD -> ground) ground
| * 492e5ce (water) water
|/
| * adba99a (air) air
|/
* 61bc9c4 (master, fire) c2
* eb0c0fc c1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground)
$ git checkout fire
Switched to branch 'fire'
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (fire)
$ vi file2
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (fire)
$ vi file2
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (fire)
$ vi file1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (fire)
$ cat file1
file1
A-B
fire
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (fire)
$ cat file2
file2
C
fire
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (fire)
$ git add f*
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (fire)
$ git commit -m "file"
[fire cfb2981] file
 2 files changed, 2 insertions(+)
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (fire)
$ logg
* cfb2981 (HEAD -> fire) file
| * 3e88a2c (ground) ground
|/
| * 492e5ce (water) water
|/
| * adba99a (air) air
|/
* 61bc9c4 (master) c2
* eb0c0fc c1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (fire)
$ vi file2
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (fire)
$ vi file1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (fire)
$ logg
* cfb2981 (HEAD -> fire) file
| * 3e88a2c (ground) ground
|/
| * 492e5ce (water) water
|/
| * adba99a (air) air
|/
* 61bc9c4 (master) c2
* eb0c0fc c1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (fire)
$ git commit -m "fireV1.0"
On branch fire
Changes not staged for commit:
        modified:   file1
        modified:   file2
no changes added to commit
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (fire)
$ git commit -am "fireV1.0"
[fire d71ddf8] fireV1.0
 2 files changed, 2 insertions(+)
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (fire)
$ logg
* d71ddf8 (HEAD -> fire) fireV1.0
* cfb2981 file
| * 3e88a2c (ground) ground
|/
| * 492e5ce (water) water
|/
| * adba99a (air) air
|/
* 61bc9c4 (master) c2
* eb0c0fc c1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (fire)
$ git checkout air
Switched to branch 'air'
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (air)
$ cat file2
file2
C
air
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (air)
$ vi file2
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (air)
$ vi file1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (air)
$ git commit -am "airV1.0"
[air 23a0b49] airV1.0
 2 files changed, 2 insertions(+)
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (air)
$ logg
* 23a0b49 (HEAD -> air) airV1.0
* adba99a air
| * d71ddf8 (fire) fireV1.0
| * cfb2981 file
|/
| * 3e88a2c (ground) ground
|/
| * 492e5ce (water) water
|/
* 61bc9c4 (master) c2
* eb0c0fc c1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (air)
$ git checkout water
Switched to branch 'water'
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (water)
$ vi file2
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (water)
$ vi file1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (water)
$ git commit -am "waterV1.0"
[water 01c630f] waterV1.0
 2 files changed, 2 insertions(+)
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (water)
$ logg
* 01c630f (HEAD -> water) waterV1.0
* 492e5ce water
| * 23a0b49 (air) airV1.0
| * adba99a air
|/
| * d71ddf8 (fire) fireV1.0
| * cfb2981 file
|/
| * 3e88a2c (ground) ground
|/
* 61bc9c4 (master) c2
* eb0c0fc c1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (water)
$ git checkout ground
Switched to branch 'ground'
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground)
$ vi file2
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground)
$ vi file1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground)
$ git commit -am "groundV1.0"
[ground 1cde227] groundV1.0
 2 files changed, 2 insertions(+)
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground)
$ logg
* 1cde227 (HEAD -> ground) groundV1.0
* 3e88a2c ground
| * 01c630f (water) waterV1.0
| * 492e5ce water
|/
| * 23a0b49 (air) airV1.0
| * adba99a air
|/
| * d71ddf8 (fire) fireV1.0
| * cfb2981 file
|/
* 61bc9c4 (master) c2
* eb0c0fc c1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground)
$ checkout master
bash: checkout: command not found
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground)
$ git checkout master
Switched to branch 'master'
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ cat file1
file1
A-B
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ cat file2
file2
C
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ vi file2
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ vi file1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ cat file2
file2
C
D
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ vi file1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git commit -am "add D"
[master 617b85c] add D
 2 files changed, 2 insertions(+), 1 deletion(-)
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ logg
* 617b85c (HEAD -> master) add D
| * 1cde227 (ground) groundV1.0
| * 3e88a2c ground
|/
| * 01c630f (water) waterV1.0
| * 492e5ce water
|/
| * 23a0b49 (air) airV1.0
| * adba99a air
|/
| * d71ddf8 (fire) fireV1.0
| * cfb2981 file
|/
* 61bc9c4 c2
* eb0c0fc c1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ cat file2
file2
C
D
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ cat file1
file1
A-B-file2:D
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git status
On branch master
nothing to commit, working tree clean
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ vi file2
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ vi file1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git commit -am "add E"
[master e0cb0f0] add E
 2 files changed, 2 insertions(+), 1 deletion(-)
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ logg
* e0cb0f0 (HEAD -> master) add E
* 617b85c add D
| * 1cde227 (ground) groundV1.0
| * 3e88a2c ground
|/
| * 01c630f (water) waterV1.0
| * 492e5ce water
|/
| * 23a0b49 (air) airV1.0
| * adba99a air
|/
| * d71ddf8 (fire) fireV1.0
| * cfb2981 file
|/
* 61bc9c4 c2
* eb0c0fc c1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git branch exclusiveFeature
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ vi fileExclusive
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ vi file1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git add f*
warning: LF will be replaced by CRLF in fileExclusive.
The file will have its original line endings in your working directory
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ ls
file1  file2  fileExclusive  gitLab01.iml  src/
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git commit -am "add exclusive feature"
[master fcba656] add exclusive feature
 2 files changed, 3 insertions(+)
 create mode 100644 fileExclusive
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ logg
* fcba656 (HEAD -> master) add exclusive feature
* e0cb0f0 (exclusiveFeature) add E
* 617b85c add D
| * 1cde227 (ground) groundV1.0
| * 3e88a2c ground
|/
| * 01c630f (water) waterV1.0
| * 492e5ce water
|/
| * 23a0b49 (air) airV1.0
| * adba99a air
|/
| * d71ddf8 (fire) fireV1.0
| * cfb2981 file
|/
* 61bc9c4 c2
* eb0c0fc c1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git checkout exclusiveFeature
Switched to branch 'exclusiveFeature'
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (exclusiveFeature)
$ logg
* fcba656 (master) add exclusive feature
* e0cb0f0 (HEAD -> exclusiveFeature) add E
* 617b85c add D
| * 1cde227 (ground) groundV1.0
| * 3e88a2c ground
|/
| * 01c630f (water) waterV1.0
| * 492e5ce water
|/
| * 23a0b49 (air) airV1.0
| * adba99a air
|/
| * d71ddf8 (fire) fireV1.0
| * cfb2981 file
|/
* 61bc9c4 c2
* eb0c0fc c1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (exclusiveFeature)
$ git checkout master
Switched to branch 'master'
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git reset --hard exclusiveFeature
HEAD is now at e0cb0f0 add E
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ logg
* e0cb0f0 (HEAD -> master, exclusiveFeature) add E
* 617b85c add D
| * 1cde227 (ground) groundV1.0
| * 3e88a2c ground
|/
| * 01c630f (water) waterV1.0
| * 492e5ce water
|/
| * 23a0b49 (air) airV1.0
| * adba99a air
|/
| * d71ddf8 (fire) fireV1.0
| * cfb2981 file
|/
* 61bc9c4 c2
* eb0c0fc c1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ cat file1
file1
A-B-file2:D-file2:E
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ cat file2
file2
C
D
E
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ ls
file1  file2  gitLab01.iml  src/
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git checkout exclusiveFeature
Switched to branch 'exclusiveFeature'
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (exclusiveFeature)
$ vi fileExclusive
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (exclusiveFeature)
$ vi file1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (exclusiveFeature)
$ ls
file1  file2  fileExclusive  gitLab01.iml  src/
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (exclusiveFeature)
$ logg
* e0cb0f0 (HEAD -> exclusiveFeature, master) add E
* 617b85c add D
| * 1cde227 (ground) groundV1.0
| * 3e88a2c ground
|/
| * 01c630f (water) waterV1.0
| * 492e5ce water
|/
| * 23a0b49 (air) airV1.0
| * adba99a air
|/
| * d71ddf8 (fire) fireV1.0
| * cfb2981 file
|/
* 61bc9c4 c2
* eb0c0fc c1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (exclusiveFeature)
$ git add f*
warning: LF will be replaced by CRLF in fileExclusive.
The file will have its original line endings in your working directory
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (exclusiveFeature)
$ git add -am "add exclusiveFeature"
error: unknown switch `a'
usage: git add [<options>] [--] <pathspec>...
    -n, --dry-run         dry run
    -v, --verbose         be verbose
    -i, --interactive     interactive picking
    -p, --patch[=<patch-mode>]
                          select hunks interactively
    -e, --edit            edit current diff and apply
    -f, --force           allow adding otherwise ignored files
    -u, --update          update tracked files
    --renormalize         renormalize EOL of tracked files (implies -u)
    -N, --intent-to-add   record only the fact that the path will be added later
    -A, --all             add changes from all tracked and untracked files
    --ignore-removal      ignore paths removed in the working tree (same as --no-all)
    --refresh             don't add, only refresh the index
    --ignore-errors       just skip files which cannot be added because of errors
    --ignore-missing      check if - even missing - files are ignored in dry run
    --chmod (+|-)x        override the executable bit of the listed files

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (exclusiveFeature)
$ git commit -am "add exclusiveFeature"
[exclusiveFeature d036688] add exclusiveFeature
 2 files changed, 3 insertions(+)
 create mode 100644 fileExclusive
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (exclusiveFeature)
$ logg
* d036688 (HEAD -> exclusiveFeature) add exclusiveFeature
* e0cb0f0 (master) add E
* 617b85c add D
| * 1cde227 (ground) groundV1.0
| * 3e88a2c ground
|/
| * 01c630f (water) waterV1.0
| * 492e5ce water
|/
| * 23a0b49 (air) airV1.0
| * adba99a air
|/
| * d71ddf8 (fire) fireV1.0
| * cfb2981 file
|/
* 61bc9c4 c2
* eb0c0fc c1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (exclusiveFeature)
$ vi fileExclusive
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (exclusiveFeature)
$ vi file1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (exclusiveFeature)
$ git commit -am "add exclusiveFeatureB"
warning: LF will be replaced by CRLF in fileExclusive.
The file will have its original line endings in your working directory
[exclusiveFeature 37a9d8e] add exclusiveFeatureB
 2 files changed, 2 insertions(+), 2 deletions(-)
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (exclusiveFeature)
$ logg
* 37a9d8e (HEAD -> exclusiveFeature) add exclusiveFeatureB
* d036688 add exclusiveFeature
* e0cb0f0 (master) add E
* 617b85c add D
| * 1cde227 (ground) groundV1.0
| * 3e88a2c ground
|/
| * 01c630f (water) waterV1.0
| * 492e5ce water
|/
| * 23a0b49 (air) airV1.0
| * adba99a air
|/
| * d71ddf8 (fire) fireV1.0
| * cfb2981 file
|/
* 61bc9c4 c2
* eb0c0fc c1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (exclusiveFeature)
$ git checkout master
Switched to branch 'master'
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ ls
file1  file2  gitLab01.iml  src/
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ logg
* 37a9d8e (exclusiveFeature) add exclusiveFeatureB
* d036688 add exclusiveFeature
* e0cb0f0 (HEAD -> master) add E
* 617b85c add D
| * 1cde227 (ground) groundV1.0
| * 3e88a2c ground
|/
| * 01c630f (water) waterV1.0
| * 492e5ce water
|/
| * 23a0b49 (air) airV1.0
| * adba99a air
|/
| * d71ddf8 (fire) fireV1.0
| * cfb2981 file
|/
* 61bc9c4 c2
* eb0c0fc c1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ vi file2
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ vi file1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git commit -am "add F"
[master 335d36b] add F
 2 files changed, 2 insertions(+)
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ logg
* 335d36b (HEAD -> master) add F
| * 37a9d8e (exclusiveFeature) add exclusiveFeatureB
| * d036688 add exclusiveFeature
|/
* e0cb0f0 add E
* 617b85c add D
| * 1cde227 (ground) groundV1.0
| * 3e88a2c ground
|/
| * 01c630f (water) waterV1.0
| * 492e5ce water
|/
| * 23a0b49 (air) airV1.0
| * adba99a air
|/
| * d71ddf8 (fire) fireV1.0
| * cfb2981 file
|/
* 61bc9c4 c2
* eb0c0fc c1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git bundle create /tmp/cherrypicklab --all
Enumerating objects: 59, done.
Counting objects: 100% (59/59), done.
Delta compression using up to 12 threads
Compressing objects: 100% (30/30), done.
Writing objects: 100% (59/59), 3.70 KiB | 421.00 KiB/s, done.
Total 59 (delta 5), reused 0 (delta 0)
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git merge exclusiveFeature
Auto-merging file1
CONFLICT (content): Merge conflict in file1
Automatic merge failed; fix conflicts and then commit the result.
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master|MERGING)
$ git diff
diff --cc file1
index f365038,d980efb..0000000
--- a/file1
+++ b/file1
@@@ -1,3 -1,3 +1,7 @@@
  file1
  A-B-file2:D-file2:E
++<<<<<<< HEAD
 +file2:F
++=======
+ fileExclusive:A-fileExclusiveB
++>>>>>>> exclusiveFeature
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master|MERGING)
$ vi file1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master|MERGING)
$ git status
On branch master
You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)
Changes to be committed:
        new file:   fileExclusive
Unmerged paths:
  (use "git add <file>..." to mark resolution)
        both modified:   file1

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master|MERGING)
$ logg
* 335d36b (HEAD -> master) add F
| * 37a9d8e (exclusiveFeature) add exclusiveFeatureB
| * d036688 add exclusiveFeature
|/
* e0cb0f0 add E
* 617b85c add D
| * 1cde227 (ground) groundV1.0
| * 3e88a2c ground
|/
| * 01c630f (water) waterV1.0
| * 492e5ce water
|/
| * 23a0b49 (air) airV1.0
| * adba99a air
|/
| * d71ddf8 (fire) fireV1.0
| * cfb2981 file
|/
* 61bc9c4 c2
* eb0c0fc c1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master|MERGING)
$ git commit
error: Committing is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.
U       file1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master|MERGING)
$ git add fi*
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master|MERGING)
$ git commit
[master f4eb0d1] Merge branch 'exclusiveFeature'
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ logg
*   f4eb0d1 (HEAD -> master) Merge branch 'exclusiveFeature'
|\
| * 37a9d8e (exclusiveFeature) add exclusiveFeatureB
| * d036688 add exclusiveFeature
* | 335d36b add F
|/
* e0cb0f0 add E
* 617b85c add D
| * 1cde227 (ground) groundV1.0
| * 3e88a2c ground
|/
| * 01c630f (water) waterV1.0
| * 492e5ce water
|/
| * 23a0b49 (air) airV1.0
| * adba99a air
|/
| * d71ddf8 (fire) fireV1.0
| * cfb2981 file
|/
* 61bc9c4 c2
* eb0c0fc c1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git checkout groung
error: pathspec 'groung' did not match any file(s) known to git
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git checkout ground
Switched to branch 'ground'
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground)
$ logg
*   f4eb0d1 (master) Merge branch 'exclusiveFeature'
|\
| * 37a9d8e (exclusiveFeature) add exclusiveFeatureB
| * d036688 add exclusiveFeature
* | 335d36b add F
|/
* e0cb0f0 add E
* 617b85c add D
| * 1cde227 (HEAD -> ground) groundV1.0
| * 3e88a2c ground
|/
| * 01c630f (water) waterV1.0
| * 492e5ce water
|/
| * 23a0b49 (air) airV1.0
| * adba99a air
|/
| * d71ddf8 (fire) fireV1.0
| * cfb2981 file
|/
* 61bc9c4 c2
* eb0c0fc c1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground)
$ git cherry-pick f4eb0d1 -m 1
error: could not apply f4eb0d1... Merge branch 'exclusiveFeature'
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground|CHERRY-PICKING)
$ git status
On branch ground
You are currently cherry-picking commit f4eb0d1.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)
Changes to be committed:
        new file:   fileExclusive
Unmerged paths:
  (use "git add <file>..." to mark resolution)
        both modified:   file1

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground|CHERRY-PICKING)
$ vi file2
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground|CHERRY-PICKING)
$ vi file1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground|CHERRY-PICKING)
$ git cherry-pick --abort
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground)
$ logg
*   f4eb0d1 (master) Merge branch 'exclusiveFeature'
|\
| * 37a9d8e (exclusiveFeature) add exclusiveFeatureB
| * d036688 add exclusiveFeature
* | 335d36b add F
|/
* e0cb0f0 add E
* 617b85c add D
| * 1cde227 (HEAD -> ground) groundV1.0
| * 3e88a2c ground
|/
| * 01c630f (water) waterV1.0
| * 492e5ce water
|/
| * 23a0b49 (air) airV1.0
| * adba99a air
|/
| * d71ddf8 (fire) fireV1.0
| * cfb2981 file
|/
* 61bc9c4 c2
* eb0c0fc c1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground)
$ git merge master
Auto-merging file2
CONFLICT (content): Merge conflict in file2
Auto-merging file1
CONFLICT (content): Merge conflict in file1
Automatic merge failed; fix conflicts and then commit the result.
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground|MERGING)
$ git diff
diff --cc file1
index 9303505,61d631b..0000000
--- a/file1
+++ b/file1
@@@ -1,4 -1,4 +1,10 @@@
  file1
++<<<<<<< HEAD
 +A-B
 +file2:ground
 +file2:groundB
++=======
+ A-B-file2:D-file2:E
+ file2:F
+ fileExclusive:A-fileExclusiveB
++>>>>>>> master
diff --cc file2
index 7797b0f,5b8b878..0000000
--- a/file2
+++ b/file2
@@@ -1,4 -1,5 +1,10 @@@
  file2
  C
++<<<<<<< HEAD
 +ground
 +groundB
++=======
+ D
+ E
+ F
++>>>>>>> master
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground|MERGING)
$ git diff --ours
* Unmerged path file1
diff --git a/file1 b/file1
index 9303505..d6502d0 100644
--- a/file1
+++ b/file1
@@ -1,4 +1,10 @@
 file1
+<<<<<<< HEAD
 A-B
 file2:ground
 file2:groundB
+=======
+A-B-file2:D-file2:E
+file2:F
+fileExclusive:A-fileExclusiveB
+>>>>>>> master
* Unmerged path file2
diff --git a/file2 b/file2
index 7797b0f..0a3a196 100644
--- a/file2
+++ b/file2
@@ -1,4 +1,10 @@
 file2
 C
+<<<<<<< HEAD
 ground
 groundB
+=======
+D
+E
+F
+>>>>>>> master
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground|MERGING)
$ git diff --theirs
* Unmerged path file1
diff --git a/file1 b/file1
index 61d631b..d6502d0 100644
--- a/file1
+++ b/file1
@@ -1,4 +1,10 @@
 file1
+<<<<<<< HEAD
+A-B
+file2:ground
+file2:groundB
+=======
 A-B-file2:D-file2:E
 file2:F
 fileExclusive:A-fileExclusiveB
+>>>>>>> master
* Unmerged path file2
diff --git a/file2 b/file2
index 5b8b878..0a3a196 100644
--- a/file2
+++ b/file2
@@ -1,5 +1,10 @@
 file2
 C
+<<<<<<< HEAD
+ground
+groundB
+=======
 D
 E
 F
+>>>>>>> master
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground|MERGING)
$ git merge --help
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground|MERGING)
$ git merge --abort
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground)
$ logg
*   f4eb0d1 (master) Merge branch 'exclusiveFeature'
|\
| * 37a9d8e (exclusiveFeature) add exclusiveFeatureB
| * d036688 add exclusiveFeature
* | 335d36b add F
|/
* e0cb0f0 add E
* 617b85c add D
| * 1cde227 (HEAD -> ground) groundV1.0
| * 3e88a2c ground
|/
| * 01c630f (water) waterV1.0
| * 492e5ce water
|/
| * 23a0b49 (air) airV1.0
| * adba99a air
|/
| * d71ddf8 (fire) fireV1.0
| * cfb2981 file
|/
* 61bc9c4 c2
* eb0c0fc c1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground)
$ git cherry-pick e0cb0f0
error: could not apply e0cb0f0... add E
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground|CHERRY-PICKING)
$ git status
On branch ground
You are currently cherry-picking commit e0cb0f0.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)
Unmerged paths:
  (use "git add <file>..." to mark resolution)
        both modified:   file1
        both modified:   file2
no changes added to commit (use "git add" and/or "git commit -a")
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground|CHERRY-PICKING)
$ git diff
diff --cc file1
index 9303505,690660f..0000000
--- a/file1
+++ b/file1
@@@ -1,4 -1,2 +1,8 @@@
  file1
++<<<<<<< HEAD
 +A-B
 +file2:ground
 +file2:groundB
++=======
+ A-B-file2:D-file2:E
++>>>>>>> e0cb0f0... add E
diff --cc file2
index 7797b0f,2ad95c6..0000000
--- a/file2
+++ b/file2
@@@ -1,4 -1,4 +1,9 @@@
  file2
  C
++<<<<<<< HEAD
 +ground
 +groundB
++=======
+ D
+ E
++>>>>>>> e0cb0f0... add E
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground|CHERRY-PICKING)
$ vi file1
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground|CHERRY-PICKING)
$ git cherry-pick --abort
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground)
$ git merge e0cb0f0
Auto-merging file2
CONFLICT (content): Merge conflict in file2
Auto-merging file1
CONFLICT (content): Merge conflict in file1
Automatic merge failed; fix conflicts and then commit the result.
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground|MERGING)
$ git diff
diff --cc file1
index 9303505,690660f..0000000
--- a/file1
+++ b/file1
@@@ -1,4 -1,2 +1,8 @@@
  file1
++<<<<<<< HEAD
 +A-B
 +file2:ground
 +file2:groundB
++=======
+ A-B-file2:D-file2:E
++>>>>>>> e0cb0f0
diff --cc file2
index 7797b0f,2ad95c6..0000000
--- a/file2
+++ b/file2
@@@ -1,4 -1,4 +1,9 @@@
  file2
  C
++<<<<<<< HEAD
 +ground
 +groundB
++=======
+ D
+ E
++>>>>>>> e0cb0f0
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground|MERGING)
$ git merge --help
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (ground|MERGING)
$ git cherry-pick --help

Before of mergin or Cherrying we do a backup with
$ git bundle create /tmp/cherrypicklab --all

in order to resume this work. we use the command

git clone /tmp/cherrypicklab newFolder

eot

martes, 8 de diciembre de 2020

GIT Demystifying part 14, rebase

GIT Demystifying part 14

rebase

Create the tree.

A failed try of rebase, then do a rebase --abort.

The correct way of do the Rebase.


Create the tree.

With rebase git allow us to rearrange the tree in order to simplify two branches into one, moving one of then to the end to the other, basically.

Let´s create a Y tree.


Opps, the commit name must be c2, lets change the name. use command: 

git commit --amend


Continue creating the tree


Finishing the tree, the tree has two branches, master and branch_01, and master has one or more commits after the common node. At this point we can merge the two branches, and this operation will be registered as a join between the two branches. With rebase the branch_01 will be moved to the end node (c5) of the other branch (master), mergin the files, and registering only one branch (master), resulting in a simple and simplified look of the tree.


A failed try of rebase, then do a rebase --abort.

  First lets do a failed rebase and learn from this situation. the correct steps to do the rebase are:

- over the branch_01 apply git rebase master.
- solve the conflicts if apply.
- git rebase --continue. At this point the branches are unified in only one, but master pointer are not on       the end of the branch.
- change to master branch.
- git rebase branch_01.  this will rewind head to the top of the now only one branch.

With this intention we do some errors, and at the end abort the rebase.


trying to commit corrected conflict over two branches. (totally wrong way, never need the commit, instead git rebase --continue).


continue



After this mesh, simply abort. 


The correct way of do the Rebase

Let´s check if the states is the correct.


Ok, seems to be ok, the file2:C must be on the master branch, we will check it when the conflict appear.

Follow this steps.

- over the branch_01 apply git rebase master.
- solve the conflicts if apply.
- git rebase --continue. At this point the branches are unified in only one, but master pointer are not on       the end of the branch.
- change to master branch.
- git rebase branch_01.  this will rewind head to the top of the now only one branch.


Now the tree is alined


Finally the rebase is done.


eot

GIT Demystifying part 13, revert a merge

GIT Demystifying part 13

Revert a merge

This operation git revert, undo the merge operation leaving a commit of this revert. 

from the previous part 12, we take the tree.



It is created a commit marqued as Revert "c5", with the same state of the master branch commit previous to the merge. Now whats happen when apply the merge again.


Nothing happend. Git has register that the merge has been doing with (branch_01) c3, so to redo the merge branch_01 again, we have to recommit the commit c3 in order to do the remerge.

checkout to master and try the merge branch_01 again.


Now, it is ready to solve the conflict manually and do the merge commit.





eot

lunes, 7 de diciembre de 2020

GIT Demystifying part 12, Branch & Merge

 GIT Demystifying part 12

Branch & Merge

Create a Y tree
git merge branch
git diff
git diff --ours
git diff --theirs
git diff --base
git checkout --conflict=diff3 filename
git log --oneline --all --decorate --graph
git log --oneline HEAD...MERGE_HEAD
git log --cc -p -1
git merge --abort

Create a Y tree

$ git init
Initialized empty Git repository in C:/Users/bext/Documents/workspaceSTS448/gitLab01/.git/

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ vi file1

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git commit -am "c1"
On branch master

Initial commit

Untracked files:
        file1

nothing added to commit but untracked files present

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git add f*
warning: LF will be replaced by CRLF in file1.
The file will have its original line endings in your working directory

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git commit -am "c1"
[master (root-commit) 2ca5b4c] c1
 1 file changed, 2 insertions(+)
 create mode 100644 file1

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ logg
* 2ca5b4c (HEAD -> master) c1

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ vi file1

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git commit -am "c2"
warning: LF will be replaced by CRLF in file1.
The file will have its original line endings in your working directory
[master 44c4ada] c2
 1 file changed, 1 insertion(+)

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ logg
* 44c4ada (HEAD -> master) c2
* 2ca5b4c c1

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git branch branch_01

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ logg
* 44c4ada (HEAD -> master, branch_01) c2
* 2ca5b4c c1

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ ls
file1  gitLab01.iml  src/

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ cat file1
file1
A
B

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git checkout branch_01
Switched to branch 'branch_01'

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (branch_01)
$ logg
* 44c4ada (HEAD -> branch_01, master) c2
* 2ca5b4c c1

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (branch_01)
$ vi file1

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (branch_01)
$ vi file2

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (branch_01)
$ cat filea
cat: filea: No such file or directory

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (branch_01)
$ cat file1
file1
A
B
file2:B

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (branch_01)
$ cat file2
file2
B

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (branch_01)
$ git add f*
warning: LF will be replaced by CRLF in file1.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in file2.
The file will have its original line endings in your working directory

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (branch_01)
$ git commit -m "c3"
[branch_01 6242885] c3
 2 files changed, 3 insertions(+)
 create mode 100644 file2

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (branch_01)
$ logg
* 6242885 (HEAD -> branch_01) c3
* 44c4ada (master) c2
* 2ca5b4c c1

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (branch_01)
$ git checkout master
Switched to branch 'master'

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ vi file1

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ vi file2

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git add f*
warning: LF will be replaced by CRLF in file2.
The file will have its original line endings in your working directory

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git commit -m "c4"
[master 0d05b4a] c4
 2 files changed, 3 insertions(+)
 create mode 100644 file2

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ cat file1
file1
A
B
file2:A

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ cat file2
file2
A

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ logg
* 0d05b4a (HEAD -> master) c4
| * 6242885 (branch_01) c3
|/
* 44c4ada c2
* 2ca5b4c c1

git merge branch
git diff
git diff --ours
git diff --theirs
git diff --base



git checkout --conflict=diff3 filename
git log --oneline --all --decorate --graph
git log --oneline HEAD...MERGE_HEAD
git log --cc -p -1



git merge --abort

  


git merge branch_01, again


Concrete the merge by commiting



eot



domingo, 6 de diciembre de 2020

GIT Demystifying part 11, Branch & Merge

GIT Demystifying part 11

Branch & Merge

Doing a merge with a tree like "Y" without data files.
Doing a merge with a tree like "Y" with data files.
To Undo the Merge.
See the effect of apply merge over the opposite branch.




Doing a merge with a tree like "Y" without data files.

command line procedure


f


Redoing the tree, but merging from master the branch, the same result.


Doing a merge with a tree like "Y" with data files.

Create a tree with one branch, one file on commit 1, and two files on the other commits.





Command line procedure


2


3


To Undo the Merge 

Now apply de command 

git reset --hard (address of commit2 "c2")

This operation set HEAD and branch master on c2, exaclty as before merge.


The content of files are as previous the merge.


See the effect of apply merge over the opposite branch

Lets checkout the branch_01 and merge master, and see the effect. for short, this will order the lines on conflict in alternate order. this mean, first the line of branch_01 followed by line of master. And set the HEAD on branch_01, where originally where called the merge.

command line procedure.


And finally to finish the merge, do the commit.




eot

sábado, 5 de diciembre de 2020

GIT Demystifying part 10, Branch & Merge

GIT Demystifying part 10, Branch & Merge
Simple Branch and Merge

Lest start with a simple trip with four commits and one branch.


To start with this lab, At directory of work clean and initialize our git.

rm -r .git

git init

Also check the directory is empty, without previos files from this lab. use the follow alias for show the commits.

alias log="git log --all --oneline --decorate --graph"

We will represent a work flow of do a work on the main branch master which is automatically created on the first commit, and then create a branch were the work will progress over an specific feature in order to be integrated on the master branch. To start, we will not work with any file, just build the road or tree to be simple example, with no conflicts to solve.


To create the tree, for short, create two commits, on the second commit, create branch_01, change HEAD to branch_01 (checkout), and create two commits more. then move the HEAD to second commit.


At this point the tree is similar with the previous frame at exception of the ids of the commits.

Merge the branch_01 into master. the merge report the message fast-forward, that is the algoritm that uses merge when the commits are on line without interruptions of branches between them.
Then recover the state previous of the merge with git reset --hard commit2, then move HEAD to branch_01 and merge master on it. The merge report Already up to date.


Now use data in commits with the same algoritm of creation and manipulation of the tree, on the progression of the data in commits do not write diferent things on same lines to simplify the sample and avoid merge conflicts for now.

$ git init
Initialized empty Git repository in C:/Users/bext/Documents/workspaceSTS448/gitLab01/.git/

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ vi file1

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git commit -m "c1"
On branch master

Initial commit

Untracked files:
        file1

nothing added to commit but untracked files present

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git add f*
warning: LF will be replaced by CRLF in file1.
The file will have its original line endings in your working directory

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git commit -m "c1"
[master (root-commit) 7a33bdd] c1
 1 file changed, 2 insertions(+)
 create mode 100644 file1

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ logg
* 7a33bdd (HEAD -> master) c1

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ vi file1

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git commit -am "c2"
warning: LF will be replaced by CRLF in file1.
The file will have its original line endings in your working directory
[master c5159ba] c2
 1 file changed, 1 insertion(+)

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ logg
* c5159ba (HEAD -> master) c2
* 7a33bdd c1

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git branch branch_01

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ logg
* c5159ba (HEAD -> master, branch_01) c2
* 7a33bdd c1

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git checkout branch_01
Switched to branch 'branch_01'

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (branch_01)
$ vi file1

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (branch_01)
$ vi file2

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (branch_01)
$ git add f*
warning: LF will be replaced by CRLF in file1.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in file2.
The file will have its original line endings in your working directory

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (branch_01)
$ git commit -m "c3"
[branch_01 025dda7] c3
 2 files changed, 3 insertions(+)
 create mode 100644 file2

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (branch_01)
$ logg
* 025dda7 (HEAD -> branch_01) c3
* c5159ba (master) c2
* 7a33bdd c1

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (branch_01)
$ vi file1

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (branch_01)
$ vi file2

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (branch_01)
$ git commit -am "c4"
warning: LF will be replaced by CRLF in file1.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in file2.
The file will have its original line endings in your working directory
[branch_01 2498b06] c4
 2 files changed, 2 insertions(+)

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (branch_01)
$ logg
* 2498b06 (HEAD -> branch_01) c4
* 025dda7 c3
* c5159ba (master) c2
* 7a33bdd c1

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (branch_01)
$ cat file1
file1
A
B
->file2 A
->file2 B

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (branch_01)
$ cat file2
file2
A
B

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (branch_01)
$ git checkout master
Switched to branch 'master'

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git merge branch_01
Updating c5159ba..2498b06
Fast-forward
 file1 | 2 ++
 file2 | 3 +++
 2 files changed, 5 insertions(+)
 create mode 100644 file2

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git status
On branch master
nothing to commit, working tree clean

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ logg
* 2498b06 (HEAD -> master, branch_01) c4
* 025dda7 c3
* c5159ba c2
* 7a33bdd c1

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git reset --hard c5159ba
HEAD is now at c5159ba c2

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ logg
* 2498b06 (branch_01) c4
* 025dda7 c3
* c5159ba (HEAD -> master) c2
* 7a33bdd c1

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ cat file1
file1
A
B

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ cat file2
cat: file2: No such file or directory

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ git checkout branch_01
Switched to branch 'branch_01'

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (branch_01)
$ logg
* 2498b06 (HEAD -> branch_01) c4
* 025dda7 c3
* c5159ba (master) c2
* 7a33bdd c1

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (branch_01)
$ git merge master
Already up to date.

The result are the same of the previous exercise with out files.


The content of the files in this sample does not generate conflict, so in any step is necesary an intervention to solve it.

When merge branch_01 into master, simply move the HEAD and master to branch_01 because there were a progessive work without interference, like never the branch_01 has been existed. more obvious is merge the master on branch_01 where is nothing to do.  


eot