历史
git reflog

- 历史版本的名称:在Git中,用HEAD表示当前版本,也就是最新的提交00c6c39,上一个版本就是HEAD^,再上一个版本就是HEAD^^,当然往上100个版本写100个^肯定就麻烦了,提供了一种简写方式为HEAD~100
对比
- 在ide中编辑df_user/models.py文件,删除str方法
from django.db import models
class UserInfo(models.Model):
uname = models.CharField(max_length=20)
upwd = models.CharField(max_length=40)
git diff HEAD -- 文件名
例:
git diff HEAD -- df_user/models.py

git add df_user/models.py
git commit -m '删除模型类的str方法'
- 在ide中编辑df_user/models.py文件,修改str方法
from django.db import models
class UserInfo(models.Model):
uname = models.CharField(max_length=20)
upwd = models.CharField(max_length=40)
def __str__(self):
return "%s" % self.uname
git add df_user/models.py
git commit -m '修改模型类的str方法为name属性'
git diff HEAD HEAD^^ -- df_user/models.py

回退
- 回退历史版本到暂存区
- 将df_user/models.py文件的更改完成添加、提交
git add df_user/models.py
git commit -m '修改模型类'
git status

- 现在,没有str方法的是当前版本为HEAD,有str方法的版本为HEAD^,将有str方法的代码恢复到暂存区
git reset HEAD^或版本号
例:
git reset HEAD^

git status

git checkout -- df_user/models.py
- 在ide中查看df_user/models.py文件,发现有str方法