Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Git: How to restore a file to a specific branches copy in a 1 liner command

Options
  • 24-06-2020 3:37pm
    #1
    Registered Users Posts: 5,576 ✭✭✭


    So my question best explained by example

    From master i branch off to branch exampleBranch

    I change 4 files a,b,c,d but then(after many changes) realise that file d was fine the way it was

    What is the quickest way to get that file exactly as it was in the master branch while keeping my other 3 changed files


Comments

  • Registered Users Posts: 17,571 ✭✭✭✭Mr. CooL ICE


    Is this relevant? Just sub in the commit number and file name


  • Registered Users Posts: 2,024 ✭✭✭Colonel Panic


    git checkout branch -- filename


  • Registered Users Posts: 2,738 ✭✭✭MyPeopleDrankTheSoup


    git show commit_hash_of_master_commit_you_branched_off -- "file_name_of_file_you_want" | git apply -R

    that won't commit, so you can play with it


Advertisement