I
I
Ivan Panteleev2013-07-09 12:24:50
git
Ivan Panteleev, 2013-07-09 12:24:50

How to remove a file from an existing commit in GIT?

For example, there is a branch with three commits, and in the second of them I need to remove the file from the index (roll it back to its original state, supposedly it has not changed). How can I do that? I suspect that you first need to execute the command git rebase -i HEAD~2, and then I don’t know ...

Answer the question

In order to leave comments, you need to log in

3 answer(s)
J
jcmvbkbc, 2013-07-09
@Yekver

I would do this:
git rebase -i HEAD~2
put edit on the commit being edited
git checkout HEAD~1
edit_file git commit -a --amend
git rebase --continue

A
alex_bel, 2013-07-09
@alex_bel

help.github.com/articles/remove-sensitive-data

B
bezgin98, 2020-07-14
@bezgin98

I do this:
git reset --soft HEAD~1 (this command cancels the commit, leaving all its changed files in the index)
Then I just remove unnecessary files from the index and re-commit only what I need
with git rabase -i I make the last commit , which needs to be fixed
About the first command, it is better written here: https://stackoverflow.com/questions/7214039/how-do...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question