如何在git中清除我的本地工作目录? [英] How do I clear my local working directory in git?

查看:1147
本文介绍了如何在git中清除我的本地工作目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在git中清除我的工作目录?

解决方案

将特定文件重置为最后提交状态放弃特定文件中的未提交更改):

  git checkout thefiletoreset.txt 

git status 输出中提到:

 (使用git checkout  - < file> ...放弃工作目录中的更改)
$ b

将整个存储库重置为上次提交状态:

  git reset --hard 

要删除未跟踪的文件,我通常只删除工作副本中的所有文件但不是 .git / 文件夹!),然后执行 git reset --hard 它只保留提交的文件。



更好的方法是使用 git clean :( Warning :使用下面的 -x 标志会导致git删除被忽略的文件。)

  git clean -d -x -f 

将删除未跟踪的文件,包括目录( -d )和git忽略的文件( -x )。将 -f 参数替换为 -n 以执行干运行或 -i 为交互模式,它会告诉你什么将被删除。



相关链接:


  • git-reset手册页

  • git-clean手册页 a>

  • git ready清理未跟踪文件(正如Marko发布的那样)
  • 你如何从你的git工作副本中删除未跟踪的文件?
    ul>

    How can I clear my working directory in git?

    解决方案

    To reset a specific file to the last-committed state (to discard uncommitted changes in a specific file):

    git checkout thefiletoreset.txt
    

    This is mentioned in the git status output:

    (use "git checkout -- <file>..." to discard changes in working directory)
    

    To reset the entire repository to the last committed state:

    git reset --hard
    

    To remove untracked files, I usually just delete all files in the working copy (but not the .git/ folder!), then do git reset --hard which leaves it with only committed files.

    A better way is to use git clean: (Warning: using the -x flag as below will cause git to delete ignored files.)

    git clean -d -x -f
    

    will remove untracked files, including directories (-d) and files ignored by git (-x). Replace the -f argument with -n to perform a dry-run or -i for interactive mode and it will tell you what will be removed.

    Relevant links:

    这篇关于如何在git中清除我的本地工作目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆