0

I have added one new file uploader.rb in my last commit. I mean this file was not present in any earlier commits. But I don't want to commit this file. In this commit with this file two old files has been committed. I have tried with git reset uploader.rb. But this is not working. Is there any way so that I can reset this file only? Thanks in advance.

Joy
  • 4,197
  • 14
  • 61
  • 131

3 Answers3

1

Assuming you did not push your modifications, I think you could try to delete the file

git rm uploader.rb
git commit -m "deleted uploader.rb"

Then perform an interactive rebase to clean your commit history

git rebase -i HEAD~2

it will display you something like this, with your two last commits:

pick f7f3f6d deleted uploader.rb
pick 310154e message of the previous commit

replace the 'pick'with a 'squash' then save

squash f7f3f6d deleted uploader.rb
pick 310154e message of the previous commit

It will merge your two commits. The one with the deletion will disappear of the history.

Otherwise, if you already pushed you modified, you modify yu commit history. You have to delete the file and commit the modification.

Pascal Le Merrer
  • 5,883
  • 20
  • 35
0

First, you need to reset your current branch to "undo" the last commit, which will leave uploader.rb and the other two files in the state they were just prior to the newest commit:

git reset HEAD^

Then recommit the two files you wanted to leave in the original commit:

git add otherfile1 otherfile2
git commit
chepner
  • 497,756
  • 71
  • 530
  • 681
0

OK, let's say that you commited good and bad, and the second shouldn't have been commited. First suppose that was the very last commit. Then you can:

git reset HEAD^     # Go back one commit, undo
git add good        # Set up to commit just the good stuff
git commit          # Redo the botched commit

If this was a few commits back, you can rewrite history to fix it up. But be careful!

git tag OldPlace        # Mark for case something explodes

gitk --all              # Show history, find the commit *before* the mess
git rebase -i SHA-FROM_ABOVE
                        # Mark the relevant commit for editing, exit the editor
                        # When you get the prompt back...
git add good
git commit              # redo...
git rebase --continue   # Rip through the other changes

git tag -d OldPlace     # Get rid of the mark, if everything is OK
vonbrand
  • 11,412
  • 8
  • 32
  • 52