3

Git 之 版本回退

 3 years ago
source link: https://segmentfault.com/a/1190000040628311
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

以前,如果是要去除某一块功能,我都是选择性删除,选择性注释,然后前后逻辑各种查看,各种比较。每一次,改完这些我总感觉心好累啊!!!然后,我就发现了 Git 一个非常强大的功能:回滚。当然我还是喜欢叫它:版本回退


1. git log

  • 定义:该命令显示从最近到最远的提交日志。每一次提交都有对应的 commit idcommit message

💡如果嫌弃输出的信息杂乱无章,那么加上 --pretty=oneline 参数试试吧!

2. git reset --hard id

  • 定义:根据 id 回退到指定的版本;
    我们已经根据 git log 命令看到了所有的提交的信息,本文中,我以回退到 个人模块修改包引入顺序 版本,即 commit id 为 7222c8f6be2d663982faa98dffe2647966b438b1;

3. git push origin HEAD --force

  • 推送到本地到远程仓库:让远程仓库代码和你本地一样,到当前你本地的版本。

这个时候突然又发现不需要回退了,刚才那些消失的代码又要重新找回来了,别担心,咱们 Git 强大着呢!

4. git reflog

  • 定义:查看命令操作的历史

  
查找到你要的 **_操作id_**,依旧使用 上文说的 **_git reset --hard id_**。又回退到当初一模一样的版本啰!



About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK