基于Git的常用撤销技巧与解决冲突方法(推荐)
作者:NiceCui 时间:2023-07-01 19:20:28
git checkout . #本地所有修改的。没有的提交的,都返回到原来的状态
git stash #把所有没有提交的修改暂存到stash里面。可用git stash pop回复。
git reset --hard HASH #返回到某个节点,不保留修改。
git reset --soft HASH #返回到某个节点。保留修改
撤销Git add操作
git reset HEAD <file> # 取消add操作并保留修改
git checkout -- <file> # 若继续该命令,则会删除掉刚刚的修改内容
撤销Git commit操作
git reset --soft <commit_id> #可以回退到某个commit并保存之前的修改 <commit_id>从git log中取,取前7位即可
git reset --hard <commit_id> #回退到某个commit不保留之前的修改
撤销Git push操作
git revert <commit_id>
原理: git revert 会产生一个新的 commit,它和指定 SHA 对应的 commit 是相反的(或者说是反转的)。 任何从原先的 commit 里删除的内容会在新的 commit 里被加回去,任何在原先的 commit 里加入的内容会在新的 commit 里被删除。这是 Git 最安全、最基本的撤销场景,因为它并不会改变历史 — 所以你现在可以 git push 新的“反转” commit 来抵消你错误提交的 commit。
Git:代码冲突常见解决方法
如果系统中有一些配置文件在服务器上做了配置修改,然后后续开发又新添加一些配置项的时候,
在发布这个配置文件的时候,会发生代码冲突:
error: Your local changes to the following files would be overwritten by merge:
protected/config/main.php
Please, commit your changes or stash them before you can merge.
如果希望保留生产服务器上所做的改动,仅仅并入新配置项, 处理方法如下:
git stash
git pull
git stash pop
然后可以使用Git diff -w +文件名 来确认代码自动合并的情况.
反过来,如果希望用代码库中的文件完全覆盖本地工作版本. 方法如下:
git reset --hard
git pull
来源:http://www.cnblogs.com/NiceCui/archive/2017/11/05/7788781.html
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
常见python正则用法的简单实例
mysql 5.7.23 winx64解压版安装教程
Python Numpy学习之索引及切片的使用方法
![](https://img.aspxhome.com/file/2023/3/120943_0s.png)
DRF使用simple JWT身份验证的实现
![](https://img.aspxhome.com/file/2023/9/133879_0s.jpg)
在JavaScript中,为什么要尽可能使用局部变量?
![](https://img.aspxhome.com/file/UploadPic/20093/1/variable_write_performance2-17s.png)
MySQL百万级数据量分页查询方法及其优化建议
Django ORM 查询表中某列字段值的方法
django上传图片并生成缩略图方法示例
利用python实现AR教程
![](https://img.aspxhome.com/file/2023/4/65844_0s.jpg)
python实现Scrapy爬取网易新闻
![](https://img.aspxhome.com/file/2023/1/93691_0s.jpg)
Django实现基于类的分页功能
![](https://img.aspxhome.com/file/2023/5/118775_0s.jpg)
解决90%的常见问题的8个python NumPy函数
![](https://img.aspxhome.com/file/2023/3/131393_0s.png)
golang 实现一个restful微服务的操作
如何做一个只搜索本网站的引擎?
inner join和left join之间的区别详解
python中的import、from import及import as的区别解析
一段重用很高的ajax代码
解决usageerror: line magic function "%%time" not found问题
![](https://img.aspxhome.com/file/2023/6/115626_0s.jpg)