如何从最新提交中删除文件?
当前回答
git checkout HEAD~ path/to/file
git commit --amend
其他回答
git checkout HEAD~ path/to/file
git commit --amend
将文件保存在本地(从gitcommit中删除)
如果要保留文件,可以使用--cached,如下所示:
git rm --cached filename
删除本地文件(并从gitcommit中删除)
否则,如果要删除文件,只需使用:
git rm filename
Here is the step to remove files from Git Commit.
>git reset --soft HEAD^1(either commitid ) -- now files moved to the staging area.
>git rm --cached filename(it will removed the file from staging area)
>git commit -m 'meaningfull message'(Now commit the required files)
最好的方法是使用SourceTree(也可以根据需要从命令行执行),并且:
检查新分支机构(出于安全原因)然后在要更改的提交之前使用gitreset-soft进行提交它将允许您删除(暂存/取消暂存)不需要的文件:)
一些对我有用的东西,但仍然认为应该有更好的解决方案:
$ git revert <commit_id>
$ git reset HEAD~1 --hard
只需将要放弃的更改保留在另一个提交中,检查其他人
$ git commit --amend // or stash and rebase to <commit_id> to amend changes
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 在Bash命令提示符上添加git分支
- 如何更改Git日志日期格式
- git pull -rebase和git pull -ff-only之间的区别