Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第 68 期(技巧):git 时光机(一) #71

Open
wingmeng opened this issue Jul 24, 2019 · 0 comments
Open

第 68 期(技巧):git 时光机(一) #71

wingmeng opened this issue Jul 24, 2019 · 0 comments

Comments

@wingmeng
Copy link
Collaborator

wingmeng commented Jul 24, 2019

玩过 RPG 游戏的小伙伴应该都知道怎么存盘(存档),有了存档,下次玩的时候,我们可以从最近的存盘点加载游戏状态,而不用重头来过。在打一些困难的 BOSS 前,我们还会手动存盘,以防万一没打过,还可以从最近的地方重新开始(SL 大法了解一下)。

Git 也是一样,你可以通过下面的方法给文件建个存档:

git add game.md  # 添加要存档的文件
git commit -m "第1关BOSS门口存档"  # 建立存档(保存快照)

每当文件修改到一定程度,你觉得有必要存个档时,就可以给它“保存一个快照”。

注意:对同一个文件提交的所有 commit(快照)都会以历史记录的形式被保存下来,新的不会覆盖旧的。

git add game.md
git commit -m "第2关打精英怪前存档"

git add game.md
git commit -m "第3关掉宝前存档"

git add game.md
git commit -m "第4关十字路口"

如果想要看存档记录呢?可以用 git log 来输出存档日志:

git log

控制台输出:

commit f9432bb61e19dea0009a8285ece0ff4a7ba1a73f
Author: wingmeng <[email protected]>
Date:   Wed Jul 24 17:43:19 2019 +0800

    第4关十字路口

commit 9ced26a67204d0b4e4661dd1d0e824a9acd13da5
Author: wingmeng <[email protected]>
Date:   Wed Jul 24 17:42:53 2019 +0800

    第3关掉宝前存档

commit 0ad987132739a525125bd987c0a7c931db6317de
Author: wingmeng <[email protected]>
Date:   Wed Jul 24 17:42:38 2019 +0800

    第2关打精英怪前存档

commit 98810af8ef54c37e1216367be0e00a98acc93f28
Author: wingmeng <[email protected]>
Date:   Wed Jul 24 17:42:21 2019 +0800

    第1关BOSS门口存档

这里共有 4 次提交记录,一旦你把文件改乱了,或者误删了文件,就可以从最近的一个 commit 恢复,而不是把所有的工作成果全部丢失。

git reset --hard e7d8c  # 恢复到“第3关掉宝前存档”
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant