Git learning notes (5)

Keywords: git

Bug branch

An interesting experiment
$ mkdir afeng

//Zhao Yafeng @ DESKTOP-0JOAFKG MINGW64 ~/Desktop
$ cd afeng

//Zhao Yafeng @ DESKTOP-0JOAFKG MINGW64 ~/Desktop/afeng
$ git init
Initialized empty Git repository in C:/Users/Zhao Yafeng/Desktop/afeng/.git/

//Zhao Yafeng @ DESKTOP-0JOAFKG MINGW64 ~/Desktop/afeng (master)
$ vi test.txt

//Zhao Yafeng @ DESKTOP-0JOAFKG MINGW64 ~/Desktop/afeng (master)
$ git add test.txt

//Zhao Yafeng @ DESKTOP-0JOAFKG MINGW64 ~/Desktop/afeng (master)
$ git commit -m "first test"
[master (root-commit) 98d217c] first test
 1 file changed, 3 insertions(+)
 create mode 100644 test.txt

//Zhao Yafeng @ desctop-0JOAFKG MINGW64 ~/Desktop/afeng (master)
$ git checkout -b dev
Switched to a new branch 'dev'

//Zhao Yafeng @ desctop-0JOAFKG MINGW64 ~/Desktop/afeng (dev)
$ vi test.txt

//Zhao Yafeng @ desctop-0JOAFKG MINGW64 ~/Desktop/afeng (dev)
$ git status
On branch dev
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   test.txt

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

//Zhao Yafeng @ desctop-0JOAFKG MINGW64 ~/Desktop/afeng (dev)
$ git stash
No local changes to save

//Zhao Yafeng @ desctop-0JOAFKG MINGW64 ~/Desktop/afeng (dev)
$ git status
On branch dev
nothing to commit, working tree clean

//Zhao Yafeng @ desctop-0JOAFKG MINGW64 ~/Desktop/afeng (dev)
$ git checkout master
Switched to branch 'master'

//Zhao Yafeng @ desctop-0JOAFKG MINGW64 ~/Desktop/afeng (master)
$ git checkout -b issue-101
Switched to a new branch 'issue-101'

//Zhao Yafeng @ desctop-0JOAFKG MINGW64 ~/Desktop/afeng (issue-101)
$ vi test.txt

//Zhao Yafeng @ desctop-0JOAFKG MINGW64 ~/Desktop/afeng (issue-101)
$ git add test.txt

//Zhao Yafeng @ desctop-0JOAFKG MINGW64 ~/Desktop/afeng (issue-101)
$ git commit -m "fix bug 101"
[issue-101 43a9dd0] fix bug 101
 1 file changed, 1 insertion(+), 1 deletion(-)

//Zhao Yafeng @ desctop-0JOAFKG MINGW64 ~/Desktop/afeng (issue-101)
$ git checkout master
Switched to branch 'master'

//Zhao Yafeng @ desctop-0JOAFKG MINGW64 ~/Desktop/afeng (master)
$ git merge --no-ff -m "merged bug fix 101" issue-101
Merge made by the 'recursive' strategy.
 test.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

//Zhao Yafeng @ desctop-0JOAFKG MINGW64 ~/Desktop/afeng (master)
$ git branch -d issue-101
Deleted branch issue-101 (was 43a9dd0).

//Zhao Yafeng @ desctop-0JOAFKG MINGW64 ~/Desktop/afeng (master)
$ git checkout dev
Switched to branch 'dev'

//Zhao Yafeng @ desctop-0JOAFKG MINGW64 ~/Desktop/afeng (dev)
$ git status
On branch dev
nothing to commit, working tree clean

//Zhao Yafeng @ desctop-0JOAFKG MINGW64 ~/Desktop/afeng (dev)
$ git stash list
stash@{0}: WIP on dev: 98d217c first test

//Zhao Yafeng @ desctop-0JOAFKG MINGW64 ~/Desktop/afeng (dev)
$ git stash pop
On branch dev
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   test.txt

no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (cf8d5889817ff7f5ebcacf7ad86799eda0959e68)

//Zhao Yafeng @ desctop-0JOAFKG MINGW64 ~/Desktop/afeng (dev)
$ git stash list

//Zhao Yafeng @ desctop-0JOAFKG MINGW64 ~/Desktop/afeng (dev)
$ cat test.txt
Git is a distributed system
Git is free software
Git trace changes

//Zhao Yafeng @ desctop-0JOAFKG MINGW64 ~/Desktop/afeng (dev)
$ git add test.txt

//Zhao Yafeng @ desctop-0JOAFKG MINGW64 ~/Desktop/afeng (dev)
$ git commit -m "work out on dev"
[dev bc0b413] work out on dev
 1 file changed, 1 insertion(+), 1 deletion(-)

//Zhao Yafeng @ desctop-0JOAFKG MINGW64 ~/Desktop/afeng (dev)
$ git checkout master
Switched to branch 'master'

//Zhao Yafeng @ desctop-0JOAFKG MINGW64 ~/Desktop/afeng (master)
$ cat test.txt
Git is a distributed system
Git is a free software

//Zhao Yafeng @ desctop-0JOAFKG MINGW64 ~/Desktop/afeng (master)
$ git merge --no-f -m "merge dev to master" dev
Auto-merging test.txt
CONFLICT (content): Merge conflict in test.txt
Automatic merge failed; fix conflicts and then commit the result.

//Zhao Yafeng @ desctop-0JOAFKG MINGW64 ~/Desktop/afeng (master|MERGING)
$ cat test.txt
Git is a distributed system
<<<<<<< HEAD
Git is a free software

=======
Git is free software
Git trace changes
>>>>>>> dev

New commands used in this experiment
git stash is used to "store" the current work site and continue to work after the site is restored.

git stash list: the storage location for viewing workspace content.

Restore the files stored by git stash command
First, use git stash apply to restore, but after the restore, the stash content will not be deleted. You need to use git stash drop to delete.
Another way is to use git stash pop, and delete the stash content while recovering.

Feature branch

Used to develop new functions, under the dev branch.
If you want to discard a branch that has not been merged, you can use git branch -D name to forcibly delete it.

Posted by feign3 on Thu, 30 Apr 2020 16:58:50 -0700