KISS

Keep It Simple Stupid

Can't reset file in git

| comments

Have you ever seen a file that git can’t reset/checkout? I have.

Here’s an example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ git status -sb
## master
 M TCPData.java

$ git reset --hard
HEAD is now at 1234567 Some commit

$ git status -sb
## master
 M TcpData.java

$ git checkout -- TcpData.java

$ git status -sb
## master
 M TcpData.java

It turned out the file was renamed in one of the branches TcpData.java => TCPData.java, and after the latest merge here is the mess. This is observed on OS X. By the way:

1
2
$ ls
TCPData.java

Here the file is with capital letters. git stores the filenames as is (case-sensitive) while the default option on the OS X’s HFS+ filesystem is case-insensitive filenames. So you have to deal with that:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$ git mv TCPData.java 1.java

$ git status -sb
## master
R  TCPData.java -> 1.java
 D TcpData.java

$ git rm TcpData.java
rm 'TcpData.java'

$ git status -sb
## master
R  TCPData.java -> 1.java
D  TcpData.java

$ git mv 1.java TCPData.java

$ git status -sb
## master
D  TcpData.java

Ha, it’s quite a twist. The git output suggests that git just removed the TcpData.java file from the current tree, which stops the mess.

Comments