git 如何撤销merge在Git中撤销一切

如果你刚刚运行了一条你不想操作的 git 命令,这个程序可以撤销该操作,告诉你如何撤销,或告诉无法撤消。
寻求撤消建议
这会在当前目录中创建 .git 文件夹。可以删除。
sudo rm -r .git
git initgitjk&这会在当前目录中创建 .git 文件夹。可以删除。sudo rm -r .git
git add file.js
This added file.js to the changes staged for commit. All changes to file.js will be removed from
staging for this commit, but remain saved in your file.
Running... git rm -r --cached file.js
git add file.jsgitjk -f&This added file.js to the changes staged for commit. All changes to file.js will be removed fromstaging for this commit, but remain saved in your file.Running... git rm -r --cached file.jsCompleted
1234567891011121314151617
add,checkout,clone,commit,diff,fetch,grep,init,log,merge,mv,pull,push,remote,rm,show,status
bisect,branch,rebase,reset,tag
You can’t just npm install! The module is named gitjk but you can set up an alias for it to pipe the last command into the program.
打赏支持我整理更多优质资源,谢谢!
打赏支持我整理更多优质资源,谢谢!
任选一种支付方式
资源整理者简介:
可能感兴趣的文章
按分类快速查找
关于资源导航
伯乐在线资源导航收录优秀的工具资源。内容覆盖开发、设计、产品和管理等IT互联网行业相关的领域。目前已经收录 1429 项工具资源。
关于资源导航
伯乐在线资源导航收录优秀的工具资源。内容覆盖开发、设计、产品和管理等IT互联网行业相关的领域。
新浪微博:
推荐微信号
(加好友请注明来意)
- 好的话题、有启发的回复、值得信赖的圈子
- 分享和发现有价值的内容与观点
- 为IT单身男女服务的征婚传播平台
- 优秀的工具资源导航
- 翻译传播优秀的外文文章
- 国内外的精选博客文章
- UI,网页,交互和用户体验
- 专注iOS技术分享
- 专注Android技术分享
- JavaScript, HTML5, CSS
- 专注Java技术分享
- 专注Python技术分享
& 2017 伯乐在线温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(11089)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
在LOFTER的更多文章
loftPermalink:'',
id:'fks_',
blogTitle:'git checkout撤销未提交的修改',
blogAbstract:'\r\n(1)&git&checkout恢复某个已修改的文件(撤销未提交的修改):$&git&checkout&file-name\r\n例如:git&checkout&src/com/android/.../xxx.java\r\n比如修改的都是java文件,不必一个个撤销,可以使用\r\n',
blogTag:'git,checkout',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:8,
publishTime:9,
permalink:'blog/static/',
commentCount:1,
mainCommentCount:1,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'',
hmcon:'0',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}如果不小心commit了一个不需要commit的文件,可以对其进行撤销。
日志信息显示如下:
WARNING: terminal is not fully functional
commit f1aca2fefd4bb93ffb64bbf2af5bc1e
Author: /****hidden****/
Thu Jun 27 14:23:52
新增PHP框架模块,此处采用 yii 框架
commit f093b6ed512f761a346e2e5c0f7c
Author: /****hidden****/
Thu Jun 27 14:05:23
创建 master,以生成 HEAD 仓
本次由于添加了错误的yii框架版本,因此需要将第二次的提交强制撤销。
找到需要回退的那次commit的 哈希值,
f093b6ed512f761a346e2e5c0f7c
git reset --hard f093b6ed512f761a346e2e5c0f7c
使用上面的命令进行回退
上述命令执行成功之后,会彻底返回到回退到的版本状态,新发生的变更将会丢失。
对于部分发生了变更,但是变更部分的文件夹存在未提交的文件可能导致目录非空而删除失败,此时需要自行处置
完成之后,使用 –force 或 -f 参数强制push(本地分支和远程分支都是 develop)
git push develop develop --force
如果你使用 TortiseGit 工具的话,它应该是不具备 reset 支持的,至少我没找到。所以 reset 操作只能在命令行模式下进行。
如果你工作在 SSH 的公钥模式下,命令行操作可能比较麻烦,我暂时不知道如何将公钥带进来提交,因为我的 gitolite服务不允许密码的,呵呵
查找了一些疑似文档,可能需要将自己的公钥添加到用户目录下的.ssh的认证文件中,未测试~~~
此时可以使用 TortiseGit 工具选择 push,并在弹出的窗口选择 force 的复选框,提交对应的分支或者全部提交,如下图:
以下是豆瓣的
苍炎的日记
起因: 不小新把记录了公司服务器IP,账号,密码的文件提交到了git
git reset --hard &commit_id&
git push origin HEAD --force
根据–soft –mixed –hard,会对working tree和index和HEAD进行重置:
git reset –mixed:此为默认方式,不带任何参数的git reset,即时这种方式,它回退到某个版本,只保留源码,回退commit和index信息
git reset –soft:回退到某个版本,只回退了commit的信息,不会恢复到index file一级。如果还要提交,直接commit即可
git reset –hard:彻底回退到某个版本,本地的源码也会变为上一个版本的内容
HEAD 最近一个提交
HEAD^ 上一次
每次commit的SHA1值. 可以用git log 看到,也可以在页面上commit标签页里找到
参考: /blog/1671638}

我要回帖

更多关于 如何撤销git add 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信