简体   繁体   English

在git commit和push之后删除不必要的文件

[英]Remove a unnecessary file after git commit and push

I did a commit and pushed the commit directly to the feature branch. 我进行了提交,并将提交直接推送到功能分支。 One of the files in the commit was not required and I need to revert the single file from commit. 不需要提交中的文件之一,我需要从提交中还原单个文件。

I tried, git reset HEAD^1 file-path and also tried, git checkout HEAD^ -- file-path to remove the file. 我尝试了git reset HEAD ^ 1文件路径,还尝试了git checkout HEAD ^-文件路径来删除文件。

When I try to amend, the status is feature branch and local has diverged and they have 1 different commit each. 当我尝试修改时,状态为功能分支且本地已分歧,它们每个都有1个不同的提交。

Help on how to commit after removing the file from commit. 从提交中删除文件后如何提交的帮助。

Will git push -f work? git push -f可以工作吗? But in my environment push force is disabled. 但是在我的环境中,推力已禁用。

I have submodule service. 我有子模块服务。

On git status, it showed - service(new commits) It contains, +Subproject commit commit-id -Subproject commit commit-id 在git status上,它显示-service(new commits)它包含+ Subproject commit commit-id -Subproject commit commit-id

In my commit by mistake this was included and pushed to branch. 在我的错误提交中,这被包括进了分支。 Is there a way to remove it. 有没有办法将其删除。

You can revert only one file to a specified revision. 您只能将一个文件还原到指定的修订版。

First you can check on which commits the file was changed. 首先,您可以检查文件已更改的提交。

git log path/to/file.txt git日志路径/到/ file.txt

Then you can checkout the file with the revision number. 然后,您可以签出带有修订号的文件。

git checkout 4cdc61015724f9965575ba954c8cd4232c8b42e4 /path/to/file.txt git checkout 4cdc61015724f9965575ba954c8cd4232c8b42e4 /path/to/file.txt

After that you can commit and push it again. 之后,您可以提交并再次推送它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM