I initialize a new repository in an empty folder:
git init
Now I copy two files A.java and B.java into this folder and commit:
git add A.java B.java && git commit -m "Added A.java and B.java to repo"
Next I create a new branch:
git branch newBranch
Afterwards I rename B.java to C.java (intentionally not using mv
) and commit on the master branch. For git it is a deletion of B.java and a creation of C.java:
git add C.java && git commit -m "Renamed B.java to C.java"
Follow on I wanna switch to my newly created branch:
git checkout newBranch
When I take a look on my working directory now B.java will be gone and only A.java exists. Why? I did the branch before the second commit. I would expect that A.java and B.java are in their original state as when I executed the branch
command. But obviously they are not and I don't understand why. Why is B.java gone?