Search code examples
gitbitbucket

Attempting to checkout old file in an older branch with file in current new branch fails


I have an old branch which no longer exists locally called MDM-991/feature-pilot. This branch is was created in 2021. I have a new branch called MDM-1112 created from the master. I want to recover a file which has undergone lots of changes from the old MDM-991/feature-pilot branch . I did a checkout of the old branch and tried the following to get the old file but it did not work:

    > git checkout MDM-1112
    > cd mdm-flow-control-plane
    > git checkout MDM-991/feature-pilot  src/main/java/com/mdm/flows/planar/FlowControlPlane.java


That is the correct path for the file when I run an ls -al command. I can navigate to it by typing at the command prompt

cd src/main/java/com/mdm/flows/planar and see the file. However,

git checkout MDM-991/feature-pilot src/main/java/com/mdm/flows/planar/FlowControlPlane.java

fails with the error:

error: pathspec 'src/main/java/com/mdm/flows/planar/FlowControlPlane.java' did not match any file(s) known to git

How is that possible? What am I doing wrong?


Solution

  • Why are you referring to a branch that doesn't exist?

    If this branch is still in the remote repository, you need to reference it

    git fetch origin
    git checkout remote/origin/MDM-991/feature-pilot -- src/main/java/com/mdm/flows/planar/FlowControlPlane.java