$ git statusOn branch masterNo commits yetnothing to commit (create/copy files and use "git add" to track)
当我们新增了一个文件之后,再查看状态, 会检测到未追踪的文件:
$ git statusOn branch masterNo commits yetUntracked files: (use "git add <file>..." to include in what will be committed) hello.txtnothing added to commit but untracked files present (use "git add" to track)
$ git add hello.txtwarning: LF will be replaced by CRLF in hello.txt.The file will have its original line endings in your working directory.
再次查看状态(检测到暂存区有新文件:)
$ git statusOn branch masterNo commits yetChanges to be committed: (use "git rm --cached <file>..." to unstage) new file: hello.txt
$ git commit -m "my first commit" hello.txtwarning: LF will be replaced by CRLF in hello.txt.The file will have its original line endings in your working directory.[master (root-commit) 86366fa] my first commit1 file changed, 16 insertions(+)create mode 100644 hello.txt
再查看状态(没有文件需要提交):
$ git statusOn branch masternothing to commit, working tree clean
$ git statusOn branch masterChanges 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: hello.txtno changes added to commit (use "git add" and/or "git commit -a")
那么接下来就需要再次将修改的文件提交到暂存区,然后提交到本地仓库。
$ git reflog087a1a7 (HEAD -> master) HEAD@{0}: commit: my third commitca8ded6 HEAD@{1}: commit: my second commit86366fa HEAD@{2}: commit (initial): my first commit
$ git reflog087a1a7 (HEAD -> master) HEAD@{0}: commit: my third commitca8ded6 HEAD@{1}: commit: my second commit86366fa HEAD@{2}: commit (initial): my first commit
--切换到 86366fa 版本,也就是我们第一次提交的版本$ git reset --hard 86366faHEAD is now at 86366fa my first commit
--切换完毕之后再查看历史记录,当前成功切换到了 86366fa 版本$ git reflog86366fa (HEAD -> master) HEAD@{0}: reset: moving to 86366fa087a1a7 HEAD@{1}: commit: my third commitca8ded6 HEAD@{2}: commit: my second commit86366fa (HEAD -> master) HEAD@{3}: commit (initial): my first commit--然后查看文件 hello.txt,发现文件内容已经变化
Git 切换版本,底层其实是移动的 HEAD 指针。