Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

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

  • 24-06-2020 03:37PM
    #1
    Registered Users, Registered Users 2 Posts: 5,761 ✭✭✭


    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,935 ✭✭✭✭Mr. CooL ICE


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


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


    git checkout branch -- filename


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