Git 使用笔记

一、 初始化

E:\>mkdir git

E:\>cd git

E:\git>git init
Initialized empty Git repository in E:/git/.git/

  • 增加一个文件readme.txt
E:\git>git add ./readme.txt

E:\git>git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached ..." to unstage)

        new file:   readme.txt


E:\git>git commit -m "add a readme"
[master (root-commit) b797535] add a readme
 1 file changed, 1 insertion(+)
 create mode 100644 readme.txt
  • 修改一处再提交
 E:\git>git commit -m "change readme"
[master 36d730c] change readme
 1 file changed, 2 insertions(+), 1 deletion(-)
  • 退回到前面两步的版本
E:\git>git reset --hard HEAD~2
HEAD is now at b797535 add a readme
  • 查看所有版本(包括被回滚覆盖的)
E:\git>git reflog
4f79e01 (HEAD -> master) HEAD@{0}: commit: change 2
2fd38c4 HEAD@{1}: commit: change 1
b797535 HEAD@{2}: reset: moving to HEAD~2
15cc4f8 HEAD@{3}: commit: change readme
36d730c HEAD@{4}: commit: change readme
b797535 HEAD@{5}: commit (initial): add a readme
  • 回到之前指定的某一个版本(无论是否已被回滚覆盖)
E:\git>git reset --hard 15cc4f8
HEAD is now at 15cc4f8 change readme

你可能感兴趣的:(Git 使用笔记)