【Git】分支-1

分支

1.创建分支

(1)创建新的工作区,初始化,创建3次提交

# mkdir lession13
# cd lession13/
# git init
# echo "aaaa" > a.txt; git add a.txt; git commit -m "add a.txt"
[master (root-commit) 7734658] add a.txt
 1 file changed, 1 insertion(+)
 create mode 100644 a.txt
# echo "bbbb" > b.txt; git add b.txt; git commit -m "add b.txt"
[master 3b39093] add b.txt
 1 file changed, 1 insertion(+)
 create mode 100644 b.txt
# echo "cccc" > c.txt; git add c.txt; git commit -m "add c.txt"
[master b70f2ff] add c.txt
 1 file changed, 1 insertion(+)
 create mode 100644 c.txt
# git log --oneline
b70f2ff add c.txt
3b39093 add b.txt
7734658 add a.txt

(2)创建新分支0.0.1,在0.0.1分支上添加新文件,提交

# git branch 0.0.1
# git checkout 0.0.1
Switched to branch '0.0.1'
# git status
# On branch 0.0.1
nothing to commit, working directory clean

# echo "dddddd" > d.txt; git add d.txt;git commit -m "add d.txt"
[0.0.1 baea88e] add d.txt
 1 file changed, 1 insertion(+)
 create mode 100644 d.txt
# git log --all --oneline --graph --decorate
* baea88e (HEAD, 0.0.1) add d.txt
* f1a337e (master) add c.txt
* d24bf92 add b.txt
* 5b693de add a.txt

(3)在master分支上,创建新的文件,并提交

# git checkout master
Switched to branch 'master'
# git log --all --decorate --oneline --graph
* 987769e (0.0.1) add d.txt
* 2123cbc (HEAD, master) add c.txt
* 796e899 add b.txt
* 622aa27 add a.txt

# echo "eeeee" >e.txt;git add e.txt;git commit -m "add e.txt"
[master 5dabc48] add e.txt
 1 file changed, 1 insertion(+)
 create mode 100644 e.txt
 
# git log --all --decorate --oneline --graph
* 5dabc48 (HEAD, master) add e.txt
| * 987769e (0.0.1) add d.txt
|/  
* 2123cbc add c.txt
* 796e899 add b.txt
* 622aa27 add a.txt

# git merge 0.0.1
Merge made by the 'recursive' strategy.
 d.txt | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 d.txt

# git log --all --graph --oneline --decorate
*   9b9c69e (HEAD, master) Merge branch '0.0.1'
|\  
| * 987769e (0.0.1) add d.txt
* | 5dabc48 add e.txt
|/  
* 2123cbc add c.txt
* 796e899 add b.txt
* 622aa27 add a.txt

总结:

  1. git branch可以创建一个分支
  2. git checkout可以切换到一个分支

2.alias

(1)创建新的工作去,3次提交,创建新的分支0.0.1,在0.0.1上做1次提交

# mkdir lession14
# cd lession14
# git init
Initialized empty Git repository in /root/git/lession14/.git/
# echo "aaaaaa" > a.txt; git add a.txt; git commit -m "add a.txt"
[master (root-commit) 622aa27] add a.txt
 1 file changed, 1 insertion(+)
 create mode 100644 a.txt
# echo "bb" > b.txt; git add b.txt; git commit -m "add b.txt"
[master 796e899] add b.txt
 1 file changed, 1 insertion(+)
 create mode 100644 b.txt
# echo "cccc" > c.txt; git add c.txt; git commit -m "add c.txt"
[master 2123cbc] add c.txt
 1 file changed, 1 insertion(+)
 create mode 100644 c.txt

# git branch 0.0.1
# git checkout 0.0.1
Switched to branch '0.0.1'
# echo "ddddd" > d.txt; git add d.txt; git commit -m "add d.txt"
[0.0.1 987769e] add d.txt
 1 file changed, 1 insertion(+)
 create mode 100644 d.txt

# git log --all --decorate --oneline --graph
* 987769e (HEAD, 0.0.1) add d.txt
* 2123cbc (master) add c.txt
* 796e899 add b.txt
* 622aa27 add a.txt

(2)将带参数的log命令配置为别名

# git config --global alias.slog "log --all --decorate --oneline --graph"
# git slog
* 987769e (HEAD, 0.0.1) add d.txt
* 2123cbc (master) add c.txt
* 796e899 add b.txt
* 622aa27 add a.txt

你可能感兴趣的:(Git)