1. 程式人生 > >Git 小結

Git 小結

一些基本操作

初始化版本庫

git init

往版本庫新增、提交檔案

git add 檔名

git commit 檔名 -m	"COMMENT"

檢視版本庫狀態

git status

檢視對比版本庫

git diff
後悔藥

1、確定回退到哪個版本

git log

$ git log
commit e475afc93c209a690c39c13a46716e8fa000c366 (HEAD -> master)
Author: Michael Liao <[email protected]>
Date:   Fri May 18 21:03:36 2018 +0800

    add distributed

commit eaadf4e385e865d25c48e7ca9c8395c3f7dfaef0
Author: Michael Liao <
[email protected]
> Date: Fri May 18 20:59:18 2018 +0800 wrote a readme file

2、回退到以前的版本

# 會退到ID為commit_id的版本

git reset --hard commit_id


# 回退上n個版本

git reset --hard HEAD~n

3、撤銷回退

# 檢視前後命令日誌

$ git reflog
e475afc [email protected]{1}: reset: moving to HEAD^
1094adb (HEAD -> master) 
[email protected]
{2}: commit: append GPL e475afc [email protected]{3}: commit: add distributed eaadf4e [email protected]{4}: commit (initial): wrote a readme file # HEAD前的即commit_id git reset --hard commit_id