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

No hay comentarios:

Publicar un comentario