Git:推送后删除提交的文件 [英] Git: Remove committed file after push

查看:721
本文介绍了Git:推送后删除提交的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有可能在Git中恢复已提交的文件?我推送了一个提交给GitHub,然后我意识到有一个我不想推送的文件(我还没有完成修改)。

解决方案

update:添加更安全的方法



首选方法:



<1>检查文件的以前(不变)状态;注意双破折号
$ b $ git checkout HEAD ^ - / path / to / file



2)提交它:

git commit -am恢复此文件的更改,尚未完成但是



<3>推送它,不需要强制:

git push



4)回到你未完成的工作,再次做(3次向上箭头):


$ b $ git checkout HEAD ^ - / path / to / file



有效'uncommitting':



要修改仓库HEAD的最后一次提交,混淆意外推送的工作,同时可能与可能已经拖动的同事发生冲突它已经变成了白发,并且失去了很多时间来试图调和他的本地分支机构与中央分支机构:

要从上次提交中删除文件更改:



1)将文件恢复到上次提交前的状态,请执行以下操作:

混帐checkout HEAD ^ / path / to / file



2)使用恢复的文件更新上次提交,请执行以下操作: b
$ b $ g $ git commit --amend



3)推送更新的提交到回购,做:

git push -f



真的,请考虑使用前面提到的首选方法。


Is there a possibility to revert a committed file in Git? I've pushed a commit to GitHub and then I realized that there's a file which I didn't want to be pushed (I haven't finished the changes).

解决方案

update: added safer method

preferred method:

1) check out the previous (unchanged) state of your file; notice the double dash

git checkout HEAD^ -- /path/to/file

2) commit it:

git commit -am "revert changes on this file, not finished with it yet"

3) push it, no force needed:

git push

4) get back to your unfinished work, again do (3 times arrow up):

git checkout HEAD^ -- /path/to/file

effectively 'uncommitting':

To modify the last commit of the repository HEAD, obfuscating your accidentally pushed work, while potentially running into a conflict with your colleague who may have pulled it already, and who will grow grey hair and lose lots of time trying to reconcile his local branch head with the central one:

To remove file change from last commit:

1) to revert the file to the state before the last commit, do:

git checkout HEAD^ /path/to/file

2) to update the last commit with the reverted file, do:

git commit --amend

3) to push the updated commit to the repo, do:

git push -f

Really, consider using the preferred method mentioned before.

这篇关于Git:推送后删除提交的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆