|
bogon:project yuanjicai$ git status
On branch master
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git checkout -- ..." to discard changes in working directory)
modified: test1.py
no changes added to commit (use "git add" and/or "git commit -a")
bogon:project yuanjicai$ cat test1.py
print 'hello world!!'
print 'hello op !!'
print 'xxxxxxxxxxx'
print 'yyyyyyyyyyy'
bogon:project yuanjicai$ git commit -am "stash commit"
[master 26415ad] stash commit
1 file changed, 2 insertions(+)
bogon:project yuanjicai$ git branch #查看分支 (*表示当前的 branch)
* master
bogon:project yuanjicai$ git branch newidea #创建分支
bogon:project yuanjicai$ git branch #再次查看分支
* master
newidea
bogon:project yuanjicai$ git checkout newidea #切换新的分支
Switched to branch 'newidea'
bogon:project yuanjicai$ cat .git/HEAD #查看当前HEAD指向newidea分支
ref: refs/heads/newidea
bogon:project yuanjicai$ ls .git/refs/heads/ #查看现有分支的存储情况
masternewidea
bogon:project yuanjicai$ cat .git/refs/heads/* #查看两个分支都指向同一个commit history
26415adb026d04fd2e375adedd6afcad8c0322ea
26415adb026d04fd2e375adedd6afcad8c0322ea
bogon:project yuanjicai$ git checkout master #现次切换回master分支
Switched to branch 'master'
bogon:project yuanjicai$ git branch -d newidea #删除指定分支
Deleted branch newidea (was 26415ad).
bogon:project yuanjicai$ git branch #再次查看分支
* master
bogon:project yuanjicai$
bogon:project yuanjicai$ git checkout -b newcode #参数-b 作用:检查如果没有branch则新建立
Switched to a new branch 'newcode'
bogon:project yuanjicai$ ls
test1.pytest4.py
bogon:project yuanjicai$ vim test1.py
bogon:project yuanjicai$ cat test1.py
print 'hello world!!'
print 'hello op !!'
print 'xxxxxxxxxxx'
print 'yyyyyyyyyyy'
print 'zzzzzzzzzzz'
bogon:project yuanjicai$ git commit -am 'newcode update'
[newcode 6c10be1] newcode update
1 file changed, 1 insertion(+)
bogon:project yuanjicai$ git checkout master
Switched to branch 'master'
bogon:project yuanjicai$ git branch
* master
newcode
bogon:project yuanjicai$ git branch -d newcode #此时删除 新分支时无法删除
error: The branch 'newcode' is not fully merged.
If you are sure you want to delete it, run 'git branch -D newcode'.
bogon:project yuanjicai$ git merge newcode #合并分支
Updating 26415ad..6c10be1
Fast-forward #合并类型为Fast-forward
test1.py | 1 +
1 file changed, 1 insertion(+)
bogon:project yuanjicai$
bogon:project yuanjicai$ git branch -d newcode #合并分支后就可以删除newcode分支了
Deleted branch newcode (was 6c10be1).
bogon:project yuanjicai$ git branch
* master
bogon:project yuanjicai$
bogon:project yuanjicai$ git checkout -b bugfix
Switched to a new branch 'bugfix'
bogon:project yuanjicai$ vim test1.py
bogon:project yuanjicai$ git commit -am 'bug fix1'
[bugfix eba1606] bug fix1
1 file changed, 1 insertion(+), 1 deletion(-)
bogon:project yuanjicai$ vim test1.py
bogon:project yuanjicai$ git commit -am 'bug fix2'
print 'hello world!!'
[bugfix 48a5fd6] bug fix2
1 file changed, 1 insertion(+), 1 deletion(-)
bogon:project yuanjicai$ git log --oneline | head -3
48a5fd6 bug fix2
eba1606 bug fix1
6c10be1 newcode update
bogon:project yuanjicai$ git checkout master
Switched to branch 'master'
bogon:project yuanjicai$ vim test1.py
bogon:project yuanjicai$ git commit -am 'last update'
[master 329577a] last update
1 file changed, 1 insertion(+), 1 deletion(-)
bogon:project yuanjicai$ git log --oneline | head -2
329577a last update
6c10be1 newcode update
bogon:project yuanjicai$ git merge bugfix #合并分支
Auto-merging test1.py
CONFLICT (content): Merge conflict in test1.py #冲突内容:合并冲突在 test1.py文件中
Automatic merge failed; fix conflicts and then commit the result. #自动合并失败;修改冲突然后提交修改后的结果
然后查看test.py源文件内容,如下
>>>>>>>>
|
|
|