Wednesday, 4 September 2019

Git Branching and Merging by Raj Gupta


Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git branch mynewbranch

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git branch -a
* master
  mynewbranch
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git checkout mynewbranch
Switched to branch 'mynewbranch'

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (mynewbranch)
$ git branch -a
  master
* mynewbranch
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (mynewbranch)
$ git log --oneline --decorate
cbb7ab4 (HEAD -> mynewbranch, origin/master, origin/HEAD, master) commit all
632f909 commit
8637d7a ignore
805a6ac Deleting new file
2678aa7 test
e144111 rename the file
5e8e01d Adding start test file
977ca2d Initial commit
34b2c44 updated file
0425ad1 update2
d8113f6 new line added
a29c62b modified index.jsp
a99e804 Update index.jsp
57a67c2 Update index.jsp
e18726d Update index.jsp
4a487a7 promotions comment
3a90027 Update index.jsp
f3ccb36 Update index.jsp
ad497a6 Update index.jsp
521d0fd modified index.jsp
73e663e modified index.jsp file for docker demo
691a7a2 modified index.jsp file
3e3afd8 Update Dockerfile
740736a Update Dockerfile
22e01c8 added docker file
1aa6466 Update index.jsp
5c693b0 latest code updated
7c81f41 Update index.jsp
4762ccd ansible added
9066612 new update
8127737 updated coc name
037bd4f updated index file
8d8c0b6 updated index file
5e95a23 Update index.jsp
a25d199 new update on index.html
438be18 Update README.md
3b7bdcd initial commit
2047f57 Create README.md

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (mynewbranch)
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git branch -m mynewbranch
fatal: A branch named 'mynewbranch' already exists.

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git branch -m mynewbranch newbranch

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git branch -a
* master
  newbranch
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git branch -d newbranch
Deleted branch newbranch (was cbb7ab4).

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git branch
* master

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git checkout -b title-change
Switched to a new branch 'title-change'

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (title-change)
$ git status
On branch title-change
nothing to commit, working tree clean

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (title-change)
$ ls
Dockerfile  pom.xml  ramu.yyy  README.md  server/  start2.txt  webapp/

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (title-change)
$ vi start2.txt

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (title-change)
$ git status
On branch title-change
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   start2.txt

no changes added to commit (use "git add" and/or "git commit -a")

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (title-change)
$ git commit -am "changes done to file"
[title-change 218d0ee] changes done to file
 1 file changed, 1 insertion(+), 1 deletion(-)

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (title-change)
$ git status
On branch title-change
nothing to commit, working tree clean

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (title-change)
$ git log --oneline
218d0ee (HEAD -> title-change) changes done to file
cbb7ab4 (origin/master, origin/HEAD, master) commit all
632f909 commit
8637d7a ignore
805a6ac Deleting new file
2678aa7 test
e144111 rename the file
5e8e01d Adding start test file
977ca2d Initial commit
34b2c44 updated file
0425ad1 update2
d8113f6 new line added
a29c62b modified index.jsp
a99e804 Update index.jsp
57a67c2 Update index.jsp
e18726d Update index.jsp
4a487a7 promotions comment
3a90027 Update index.jsp
f3ccb36 Update index.jsp
ad497a6 Update index.jsp
521d0fd modified index.jsp
73e663e modified index.jsp file for docker demo
691a7a2 modified index.jsp file
3e3afd8 Update Dockerfile
740736a Update Dockerfile
22e01c8 added docker file
1aa6466 Update index.jsp
5c693b0 latest code updated
7c81f41 Update index.jsp
4762ccd ansible added
9066612 new update
8127737 updated coc name
037bd4f updated index file
8d8c0b6 updated index file
5e95a23 Update index.jsp
a25d199 new update on index.html
438be18 Update README.md
3b7bdcd initial commit
2047f57 Create README.md

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (title-change)
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git diff master title-change
diff --git a/start2.txt b/start2.txt
index 52d986d..1fb25fb 100644
--- a/start2.txt
+++ b/start2.txt
@@ -1 +1 @@
-qThis is Git Quick Start demo
+This is Git Quick Start demo

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git difftool master title-change

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git merge title-change
Updating cbb7ab4..218d0ee
Fast-forward
 start2.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git difftool master title-change

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git diff master title-change

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git log --oneline --graph --decorate
* 218d0ee (HEAD -> master, title-change) changes done to file
* cbb7ab4 (origin/master, origin/HEAD) commit all
* 632f909 commit
* 8637d7a ignore
* 805a6ac Deleting new file
* 2678aa7 test
* e144111 rename the file
* 5e8e01d Adding start test file
* 977ca2d Initial commit
* 34b2c44 updated file
* 0425ad1 update2
* d8113f6 new line added
* a29c62b modified index.jsp
* a99e804 Update index.jsp
* 57a67c2 Update index.jsp
* e18726d Update index.jsp
* 4a487a7 promotions comment
* 3a90027 Update index.jsp
* f3ccb36 Update index.jsp
* ad497a6 Update index.jsp
* 521d0fd modified index.jsp
* 73e663e modified index.jsp file for docker demo
* 691a7a2 modified index.jsp file
* 3e3afd8 Update Dockerfile
* 740736a Update Dockerfile
* 22e01c8 added docker file
* 1aa6466 Update index.jsp
* 5c693b0 latest code updated
* 7c81f41 Update index.jsp
* 4762ccd ansible added
* 9066612 new update
* 8127737 updated coc name
* 037bd4f updated index file
* 8d8c0b6 updated index file
* 5e95a23 Update index.jsp
* a25d199 new update on index.html
* 438be18 Update README.md
* 3b7bdcd initial commit
* 2047f57 Create README.md

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git branch
* master
  title-change

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git branch -d title-change
Deleted branch title-change (was 218d0ee).

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git branch
* master

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git log --oneline --graph --decorate
* 218d0ee (HEAD -> master) changes done to file
* cbb7ab4 (origin/master, origin/HEAD) commit all
* 632f909 commit
* 8637d7a ignore
* 805a6ac Deleting new file
* 2678aa7 test
* e144111 rename the file
* 5e8e01d Adding start test file
* 977ca2d Initial commit
* 34b2c44 updated file
* 0425ad1 update2
* d8113f6 new line added
* a29c62b modified index.jsp
* a99e804 Update index.jsp
* 57a67c2 Update index.jsp
* e18726d Update index.jsp
* 4a487a7 promotions comment
* 3a90027 Update index.jsp
* f3ccb36 Update index.jsp
* ad497a6 Update index.jsp
* 521d0fd modified index.jsp
* 73e663e modified index.jsp file for docker demo
* 691a7a2 modified index.jsp file
* 3e3afd8 Update Dockerfile
* 740736a Update Dockerfile
* 22e01c8 added docker file
* 1aa6466 Update index.jsp
* 5c693b0 latest code updated
* 7c81f41 Update index.jsp
* 4762ccd ansible added
* 9066612 new update
* 8127737 updated coc name
* 037bd4f updated index file
* 8d8c0b6 updated index file
* 5e95a23 Update index.jsp
* a25d199 new update on index.html
* 438be18 Update README.md
* 3b7bdcd initial commit
* 2047f57 Create README.md

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git checkout -b add-copyright
Switched to a new branch 'add-copyright'

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (add-copyright)
$ git branch
* add-copyright
  master

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (add-copyright)
$ ls
Dockerfile  pom.xml  ramu.yyy  README.md  server/  start2.txt  webapp/

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (add-copyright)
$ vi start2.txt

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (add-copyright)
$ git status
On branch add-copyright
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   start2.txt

no changes added to commit (use "git add" and/or "git commit -a")

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (add-copyright)
$ git commit -am "Adding copyright notice"
[add-copyright 8746b9d] Adding copyright notice
 1 file changed, 1 insertion(+), 1 deletion(-)

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (add-copyright)
$ git status
On branch add-copyright
nothing to commit, working tree clean

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (add-copyright)
$ vi README.md

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (add-copyright)
$ git status
On branch add-copyright
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   README.md

no changes added to commit (use "git add" and/or "git commit -a")

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (add-copyright)
$ git commit -am "adding line"
[add-copyright de62fc3] adding line
 1 file changed, 1 insertion(+), 1 deletion(-)

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (add-copyright)
$ git status
On branch add-copyright
nothing to commit, working tree clean

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (add-copyright)
$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git merge add-copyright --no-off
error: unknown option `no-off'
usage: git merge [<options>] [<commit>...]
   or: git merge --abort
   or: git merge --continue

    -n                    do not show a diffstat at the end of the merge
    --stat                show a diffstat at the end of the merge
    --summary             (synonym to --stat)
    --log[=<n>]           add (at most <n>) entries from shortlog to merge commit message
    --squash              create a single commit instead of doing a merge
    --commit              perform a commit if the merge succeeds (default)
    -e, --edit            edit message before committing
    --cleanup <mode>      how to strip spaces and #comments from message
    --ff                  allow fast-forward (default)
    --ff-only             abort if fast-forward is not possible
    --rerere-autoupdate   update the index with reused conflict resolution if possible
    --verify-signatures   verify that the named commit has a valid GPG signature
    -s, --strategy <strategy>
                          merge strategy to use
    -X, --strategy-option <option=value>
                          option for selected merge strategy
    -m, --message <message>
                          merge commit message (for a non-fast-forward merge)
    -F, --file <path>     read message from file
    -v, --verbose         be more verbose
    -q, --quiet           be more quiet
    --abort               abort the current in-progress merge
    --quit                --abort but leave index and working tree alone
    --continue            continue the current in-progress merge
    --allow-unrelated-histories
                          allow merging unrelated histories
    --progress            force progress reporting
    -S, --gpg-sign[=<key-id>]
                          GPG sign commit
    --overwrite-ignore    update ignored files (default)
    --signoff             add Signed-off-by:
    --verify              verify commit-msg hook


Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git merge add-copyright --no-ff
Merge made by the 'recursive' strategy.
 README.md  | 2 +-
 start2.txt | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git branch -d add-copyright
Deleted branch add-copyright (was de62fc3).

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git branch
* master

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 4 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git checkout -b simple-changes
Switched to a new branch 'simple-changes'

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (simple-changes)
$ ll
total 12
-rw-r--r-- 1 Administrator 197121  133 Aug 29 07:52 Dockerfile
-rw-r--r-- 1 Administrator 197121 5969 Aug 29 07:52 pom.xml
-rw-r--r-- 1 Administrator 197121    4 Aug 29 09:40 ramu.yyy
-rw-r--r-- 1 Administrator 197121   54 Sep  3 10:41 README.md
drwxr-xr-x 1 Administrator 197121    0 Aug 29 07:52 server/
-rw-r--r-- 1 Administrator 197121   30 Sep  3 10:41 start2.txt
drwxr-xr-x 1 Administrator 197121    0 Aug 29 07:52 webapp/

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (simple-changes)
$ vi start2.txt

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (simple-changes)
$ git status
On branch simple-changes
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   start2.txt

no changes added to commit (use "git add" and/or "git commit -a")

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (simple-changes)
$ git commit -am "adding"
[simple-changes 7fffcc8] adding
 1 file changed, 1 insertion(+), 1 deletion(-)

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (simple-changes)
$ git status
On branch simple-changes
nothing to commit, working tree clean

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (simple-changes)
$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 4 commits.
  (use "git push" to publish your local commits)

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ vi README.md

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 4 commits.
  (use "git push" to publish your local commits)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   README.md

no changes added to commit (use "git add" and/or "git commit -a")

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git commit -am "adding"
[master 7277340] adding
 1 file changed, 1 insertion(+), 1 deletion(-)

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 5 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git log --oneline --graph --decorate --all
* 7277340 (HEAD -> master) adding
| * 7fffcc8 (simple-changes) adding
|/
*   39c29d9 Merge branch 'add-copyright' Raj
|\
| * de62fc3 adding line
| * 8746b9d Adding copyright notice
|/
* 218d0ee changes done to file
* cbb7ab4 (origin/master, origin/HEAD) commit all
* 632f909 commit
* 8637d7a ignore
* 805a6ac Deleting new file
* 2678aa7 test
* e144111 rename the file
* 5e8e01d Adding start test file
* 977ca2d Initial commit
* 34b2c44 updated file
* 0425ad1 update2
* d8113f6 new line added
* a29c62b modified index.jsp
* a99e804 Update index.jsp
* 57a67c2 Update index.jsp
* e18726d Update index.jsp
* 4a487a7 promotions comment
* 3a90027 Update index.jsp
* f3ccb36 Update index.jsp
* ad497a6 Update index.jsp
* 521d0fd modified index.jsp
* 73e663e modified index.jsp file for docker demo
* 691a7a2 modified index.jsp file
* 3e3afd8 Update Dockerfile
* 740736a Update Dockerfile
* 22e01c8 added docker file
* 1aa6466 Update index.jsp
* 5c693b0 latest code updated
* 7c81f41 Update index.jsp
* 4762ccd ansible added
* 9066612 new update
* 8127737 updated coc name
* 037bd4f updated index file
* 8d8c0b6 updated index file
* 5e95a23 Update index.jsp
* a25d199 new update on index.html
* 438be18 Update README.md
* 3b7bdcd initial commit
* 2047f57 Create README.md

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git branch
* master
  simple-changes

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git merge simple-changes -m "Merging changes from simple-changes brance"
Merge made by the 'recursive' strategy.
 start2.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git log --oneline --graph --decorate --all
*   9fc9b59 (HEAD -> master) Merging changes from simple-changes brance
|\
| * 7fffcc8 (simple-changes) adding
* | 7277340 adding
|/
*   39c29d9 Merge branch 'add-copyright' Raj
|\
| * de62fc3 adding line
| * 8746b9d Adding copyright notice
|/
* 218d0ee changes done to file
* cbb7ab4 (origin/master, origin/HEAD) commit all
* 632f909 commit
* 8637d7a ignore
* 805a6ac Deleting new file
* 2678aa7 test
* e144111 rename the file
* 5e8e01d Adding start test file
* 977ca2d Initial commit
* 34b2c44 updated file
* 0425ad1 update2
* d8113f6 new line added
* a29c62b modified index.jsp
* a99e804 Update index.jsp
* 57a67c2 Update index.jsp
* e18726d Update index.jsp
* 4a487a7 promotions comment
* 3a90027 Update index.jsp
* f3ccb36 Update index.jsp
* ad497a6 Update index.jsp
* 521d0fd modified index.jsp
* 73e663e modified index.jsp file for docker demo
* 691a7a2 modified index.jsp file
* 3e3afd8 Update Dockerfile
* 740736a Update Dockerfile
* 22e01c8 added docker file
* 1aa6466 Update index.jsp
* 5c693b0 latest code updated
* 7c81f41 Update index.jsp
* 4762ccd ansible added
* 9066612 new update
* 8127737 updated coc name
* 037bd4f updated index file
* 8d8c0b6 updated index file
* 5e95a23 Update index.jsp
* a25d199 new update on index.html
* 438be18 Update README.md
* 3b7bdcd initial commit
* 2047f57 Create README.md

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git branch -d simple-changes
Deleted branch simple-changes (was 7fffcc8).

No comments:

Post a Comment