michael
michael

Reputation: 110620

How can I remove a change in 1 file in 1 commit

I change 3 files in my git commit. I don't understand:

  1. why git thinks I change in the following file? The diff shows no difference.

  2. how can i remove this file change in my git commit?

    diff --git a/src/StateListener.java b/src/StateListener.java
    index 0125c44..6ba0874 100644
    --- a/src/StateListener.java
    +++ b/src/StateListener.java
    @@ -7,8 +7,8 @@ import android.telephony.PhoneStateListener;
    import android.telephony.TelephonyManager;
    import android.util.Log;
    
    -public class StateListener extends PhoneStateListener {
    
    +public class StateListener extends PhoneStateListener {
     private Context mContext;
    

Upvotes: 1

Views: 179

Answers (2)

alexvassel
alexvassel

Reputation: 10740

Use "git checkout src/StateListener.java" to discard changes in working directory.

Upvotes: 2

wich
wich

Reputation: 17157

It is probably a whitespace change, undo the change and git commit --amend it.

Alternatively do the following:

$ git reset --soft HEAD^
$ git checkout -f src/StateListener.java
$ git commit -c ORIG_HEAD

Upvotes: 3

Related Questions