Can I use “git checkout --” on two files?

前端 未结 6 1049
时光取名叫无心
时光取名叫无心 2020-12-10 10:00

Is it possible to use git checkout -- on multiple files in order to discard the changes?

If so how would I specify multiple files?

6条回答
  •  时光说笑
    2020-12-10 10:37

    I accidentally modified all files in a directory by running find in my user's git repo directory.

    me@server:/home/me/gitrepo# git status
    On branch master
    Your branch is up-to-date with 'origin/master'.
    
    Changes not staged for commit:
      (use "git add ..." to update what will be committed)
      (use "git checkout -- ..." to discard changes in working directory)
    
        modified:   .bashrc
        modified:   dir/ec2-user.pem
        modified:   dir/readme.txt
        modified:   dir/root.pem
        modified:   dir/ec2-user.pem
        modified:   dir/readme.txt
        modified:   dir/root.pem
        modified:   dir/ec2-user.pem
        modified:   dir/ec2-user.pem.pub
        modified:   dir/readme.txt
        modified:   dir/root.pem
    

    To correct my mistake I ran something like this command to find all modified files and checkout the files from master.

    git status | grep modified | sed 's/^.*modified: //' | xargs git checkout

提交回复
热议问题