Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

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

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


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


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


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


    git checkout branch -- filename


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