是否可以使用git checkout - 在多个文件上放弃更改?如果是这样,我将如何指定多个文件.谢谢.
sja*_*agr 59
多次运行该命令
git checkout -- path/to/file/one
git checkout -- path/to/file/two
Run Code Online (Sandbox Code Playgroud)
或者在同一行中指定多个文件:
git checkout -- path/to/file/one path/to/file/two
Run Code Online (Sandbox Code Playgroud)
您还可以指定整个文件夹,这些文件夹将递归到它们下面的所有文件.
git checkout -- path/to/folder
git checkout -- . # for the current path
Run Code Online (Sandbox Code Playgroud)
小智 6
我在用户的git repo目录中运行find,意外地修改了目录中的所有文件.
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 <file>..." to update what will be committed)
(use "git checkout -- <file>..." 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
Run Code Online (Sandbox Code Playgroud)
为了纠正我的错误,我运行了类似这个命令的东西来查找所有修改过的文件并从master中检出文件.
git status | grep modified | sed 's/^.*modified: //' | xargs git checkout