3

Here is what I messed up so far,

  1. I copied (not cloned) a rails project from windows to linux pc

  2. Then created a new branch and made lots of changes

  3. At last commited twice whole project and pushed it to a remote repository with windows line endings.

Problem: so my problem is that, since I copied the project from windows to linux, when I run git status whole project shows modified. I don't see the changes I made specifically. Since I committed and pushed whole project, I lost history of files change.

What is needed: So I want to remove my last two commit but I want to keep my changes that I made. Then I want to convert the line endings from windows to unix of whole project so that when I run git status I see only the files that I changed, not whole project. And then I want to commit and push to remote.

It would be nice if there is a solution for this mess.

I am not sure if this will be helpful, I am working on a rails project and my IDE is rubymine.

2 Answers2

0

To undo your last two commits run this:

  1. git reset --soft HEAD~2. This will put the files involved in the commits into your working directory.
  2. Run git status and they will show as staged changes (ready for commit).
  3. Edit your files.
  4. Stage and commit your changes. Important: Don't push
  5. Run git pull.
  6. Run git push

Make sure you commit your changes and do a git pull prior to git push, otherwise your attempt to push will cause conflict and will be rejected.

HenryTK
  • 1,287
  • 8
  • 11
  • I have been reading about git commands and it seems that I should use git revert instead of git reset since I already pushed my commits. –  Jan 18 '16 at 11:30
  • @user1670773 My experience of `git revert` is limited so I cannot advise further. All I know is I have used and tested the approach detailed above, but that is not to say it is the 'correct' way. – HenryTK Jan 18 '16 at 17:04
-1

You can use git filter-branch. Similar question here.

Community
  • 1
  • 1
Arnie97
  • 1,020
  • 7
  • 19