简体   繁体   English

撤消所有本地提交但尚未推送的git文件

[英]undo all local committed yet not pushed files in git

For test purpose, I have created two files respectively, "admin/1.txt" and "user/2.txt", my command flow is as below: 为了进行测试,我分别创建了两个文件“ admin / 1.txt”和“ user / 2.txt”,命令流程如下:

git add admin/* git commit -m "first commit" git add user/* git commit -m "second commit"

This local commit process could happen multiple times. 此本地提交过程可能会发生多次。 But after that, I need to rollback all these local-committed-yet-not-pushed files back to there start state (untracked or modified), how could I do that in one line of command? 但是之后,我需要将所有这些尚未提交的本地提交的文件回滚到开始状态(未跟踪或已修改),如何在一行命令中做到这一点? I've tried git reset HEAD~1 , but it only rollback 1 step, not all local commitments. 我试过git reset HEAD~1 ,但是它只回滚1步,而不是所有本地承诺。 Any ideas? 有任何想法吗? Thanks. 谢谢。

使用git checkout -b new_branch将您未提交的更改保存在新分支中,然后返回到以前的分支,然后使用git reset --hard origin/master

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM