13.进一步理解HEAD和branch

用到的命令:
git log 查看所以当下分支的所有commit信息
git checkout 59486d392cc8643 切换到某个commit分支上
vi styles/style.css 编辑这个文件(按 i 可以进入编辑插入状态,按ESC退出编辑插入模式,输入 wq! 保存并退出到命令行界面 )
git status 查看文件的状态是否被更改
git add style.css 将变更文件提交到暂存区
git commit -m'说明' 把文件从暂存区提交到git上
以上两个命令可以变成一个:git commit -am'说明'
git branch -av 查看当前的所有分支
gitk -all 跳转到gitk的图形界面并直观地显示所有的分支
git branch fix_css 69697ba 创建名为fix_css的分支69697ba

Administrator@WIN-KF4CHDSKKH5 MINGW64 ~/Desktop/git-learning/git_learning (master)
$ git log
commit a68037ead938c0acc792c70da1e0a5ab6ac4d2ca (HEAD -> master, fix_readme)
Author: crj <[email protected]>
Date:   Tue Dec 11 09:41:10 2018 +0800

    readme.txt to readme.md

commit 449a5d61003c986ec2516aa2fc37e12bfe767e7c
Author: crj <[email protected]>
Date:   Tue Dec 11 00:19:41 2018 +0800

    Add refering projects

commit aec5d5c5572b1b31459ac7cf9029bfa6437e4700
Author: crj <[email protected]>
Date:   Mon Dec 10 23:58:28 2018 +0800

    add js

commit 59486d392cc864377dae7889ea19305dd486bac3
Author: crj <[email protected]>
Date:   Mon Dec 10 23:51:30 2018 +0800

    Add style

commit 9c2763dd17c4ed21233616a965e6702d39dfd346
Author: crj <[email protected]>
Date:   Mon Dec 10 23:43:01 2018 +0800

    Add index + logo

commit 321da61f9dac1e4126e3ccff38ae2a231264e8cf
Author: crj <[email protected]>
Date:   Mon Dec 10 22:49:35 2018 +0800

    Add readme.txt

Administrator@WIN-KF4CHDSKKH5 MINGW64 ~/Desktop/git-learning/git_learning (master)
$ git checkout 59486d392cc8643
Note: checking out '59486d392cc8643'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b 

HEAD is now at 59486d3 Add style

Administrator@WIN-KF4CHDSKKH5 MINGW64 ~/Desktop/git-learning/git_learning ((59486d3...))
$ ls -al
total 16
drwxr-xr-x 1 Administrator 197121    0 12月 11 14:05 ./
drwxr-xr-x 1 Administrator 197121    0 12月 11 11:24 ../
drwxr-xr-x 1 Administrator 197121    0 12月 11 14:05 .git/
drwxr-xr-x 1 Administrator 197121    0 12月 11 13:56 images/
-rw-r--r-- 1 Administrator 197121 1352 12月 11 14:05 index.html
-rw-r--r-- 1 Administrator 197121    0 12月 11 14:05 readme.txt
drwxr-xr-x 1 Administrator 197121    0 12月 11 14:05 styles/

Administrator@WIN-KF4CHDSKKH5 MINGW64 ~/Desktop/git-learning/git_learning ((59486d3...))
$ vi styles/style.css

Administrator@WIN-KF4CHDSKKH5 MINGW64 ~/Desktop/git-learning/git_learning ((59486d3...))
$ git status
HEAD detached at 59486d3
Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git checkout -- ..." to discard changes in working directory)

        modified:   styles/style.css

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

Administrator@WIN-KF4CHDSKKH5 MINGW64 ~/Desktop/git-learning/git_learning ((59486d3...))
$ git commit -am'Background to green'
[detached HEAD 69697ba] Background to green
 1 file changed, 1 insertion(+), 1 deletion(-)

Administrator@WIN-KF4CHDSKKH5 MINGW64 ~/Desktop/git-learning/git_learning ((69697ba...))
$ git log
commit 69697bafa4fc3213b70cc24e44a14c2db379dec6 (HEAD)
Author: crj <[email protected]>
Date:   Tue Dec 11 14:08:36 2018 +0800

    Background to green

commit 59486d392cc864377dae7889ea19305dd486bac3
Author: crj <[email protected]>
Date:   Mon Dec 10 23:51:30 2018 +0800

    Add style

commit 9c2763dd17c4ed21233616a965e6702d39dfd346
Author: crj <[email protected]>
Date:   Mon Dec 10 23:43:01 2018 +0800

    Add index + logo

commit 321da61f9dac1e4126e3ccff38ae2a231264e8cf
Author: crj <[email protected]>
Date:   Mon Dec 10 22:49:35 2018 +0800

    Add readme.txt

Administrator@WIN-KF4CHDSKKH5 MINGW64 ~/Desktop/git-learning/git_learning ((69697ba...))
$ git branch -av
* (HEAD detached from 59486d3) 69697ba Background to green
  fix_readme                   a68037e readme.txt to readme.md
  master                       a68037e readme.txt to readme.md

Administrator@WIN-KF4CHDSKKH5 MINGW64 ~/Desktop/git-learning/git_learning ((69697ba...))
$ git checkout master
Warning: you are leaving 1 commit behind, not connected to
any of your branches:

  69697ba Background to green

If you want to keep it by creating a new branch, this may be a good time
to do so with:

 git branch  69697ba

Switched to branch 'master'

Administrator@WIN-KF4CHDSKKH5 MINGW64 ~/Desktop/git-learning/git_learning (master)
$ gitk --all

Administrator@WIN-KF4CHDSKKH5 MINGW64 ~/Desktop/git-learning/git_learning (master)
$ git branch fix_css 69697ba

Administrator@WIN-KF4CHDSKKH5 MINGW64 ~/Desktop/git-learning/git_learning (master)
$ gitk --all

Administrator@WIN-KF4CHDSKKH5 MINGW64 ~/Desktop/git-learning/git_learning (master)
$

你可能感兴趣的:(13.进一步理解HEAD和branch)