git 撤销操作

来源:互联网 发布:网络零售的特点与模式 编辑:程序博客网 时间:2024/05/01 22:02

1. 修改最后一次提交

使用命令:

git commit --amend

加上--amend相当于使用暂存区域快照提交。

git commit -m 'first commit'git add some_filegit commit --amend

最终只产生一次提交

2. 取消对文件的修改

使用命令:

git checkout -- filename

3. 取消已经add的文件

git reset HEAD filename

4. 取消已经commit的文件

git reset <commit_id>

可以加参数--soft,--mixed--head。默认为--mixed
--soft:只回退commit信息
--mixed:保留源代码,回退commit和index信息
--head:回退源代码

5. 删除已经push

git revert <SHA>
0 0
原创粉丝点击