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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

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

  • 24-06-2020 2:37pm
    #1
    Registered Users, Registered Users 2 Posts: 5,659 ✭✭✭


    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, Registered Users 2 Posts: 17,708 ✭✭✭✭Mr. CooL ICE


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


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


    git checkout branch -- filename


  • Registered Users, Registered Users 2 Posts: 2,751 ✭✭✭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