简体   繁体   中英

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.

When I try to amend, the status is feature branch and local has diverged and they have 1 different commit each.

Help on how to commit after removing the file from commit.

Will git push -f work? 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

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

Then you can checkout the file with the revision number.

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

After that you can commit and push it again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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