博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何清除Git中的本地工作目录? [重复]
阅读量:2290 次
发布时间:2019-05-09

本文共 2946 字,大约阅读时间需要 9 分钟。

本文翻译自:

This question already has an answer here: 这个问题在这里已有答案:

  • 35 answers 35中

How can I clear my working directory in Git? 如何在Git中清除我的工作目录?


#1楼

参考:


#2楼

All the answers so far retain local commits. 到目前为止,所有答案都保留了本地提交。 If you're really serious, you can discard all local commits and all local edits by doing: 如果您真的很认真,可以通过以下方式丢弃所有本地提交和所有本地编辑:

git reset --hard origin/branchname

For example: 例如:

git reset --hard origin/master

This makes your local repository exactly match the state of the origin (other than untracked files). 这使您的本地存储库原始状态(未跟踪文件除外) 完全匹配

If you accidentally did this after just reading the command, and not what it does :), use git reflog to find your old commits. 如果您在阅读完命令之后意外地执行了此操作,而不是它的操作:),请使用git reflog查找旧的提交。


#3楼

You could create a commit which contains an empty working copy. 您可以创建一个包含空工作副本的提交。

This is a generally safe, non-destructive approach because it does not involve the use of any brute-force reset mechanisms. 这是一种通常安全,非破坏性的方法,因为它不涉及使用任何强力复位机制。 First you hide all managed content with git checkout empty , then you are free to manually review and remove whatever unmanaged content remains. 首先,您将所有托管内容隐藏为git checkout empty ,然后您可以自由查看并删除任何未管理的内容。

## create a stand-alone, tagged, empty committrue | git mktree | xargs git commit-tree | xargs git tag empty## clear the working copygit checkout empty

Your working copy should now be clear of any managed content. 您的工作副本现在应该清除任何托管内容。 All that remains are unmanaged files and the .git folder itself. 剩下的就是非托管文件和.git文件夹本身。

To re-populate your working copy... 要重新填充您的工作副本......

git checkout master ## or whatever branch you will be using

If you're a forward thinking individual, you might start your repository off on the right foot by basing everything on an initial empty commit... 如果你是一个具有前瞻思维的人,你可以通过将所有内容都放在最初的空提交中来启动你的知识库。

git initgit commit --allow-empty --allow-empty-message -m ""git tag empty...

There are various uses for a tagged empty worktree. 标记的空工作树有各种用途。 My favorite at the moment is to depopulate the root under a set of git worktree subfolders. 我最喜欢的是在一组git worktree子文件夹下减少root。


#4楼

To reset a specific file as git status suggests: 要将特定文件重置为git status建议:

git checkout 

To reset a folder 要重置文件夹

git checkout 
/*

#5楼

To switch to another branch, discarding all uncommitted changes (eg resulting from Git's strange handling of line endings): 要切换到另一个分支,丢弃所有未提交的更改(例如,由Git奇怪处理行结尾):

git checkout -f 

I had a working copy with hundreds of changed files (but empty git diff --ignore-space-at-eol ) which I couldn't get rid off with any of the commands I read here, and git checkout <branchname> won't work, either - unless given the -f (or --force ) option. 我有一个包含数百个已更改文件的工作副本(但是空的git diff --ignore-space-at-eol ),我无法用我在这里读到的任何命令摆脱它, git checkout <branchname> won' --force工作 - 除非给出-f (或--force )选项。


#6楼

Use: 使用:

git clean -df

It's not well advertised, but git clean is really handy. 它没有得到很好的宣传,但git clean非常方便。 Git Ready has a . Git Ready 有一个 。

转载地址:http://pjcnb.baihongyu.com/

你可能感兴趣的文章
TCP/IP协议卷一 契约 (部分内容)
查看>>
Java 内存管理和垃圾回收机制
查看>>
iOS invalid bitcode signature等常见错误
查看>>
iOS 开发常用的代码块
查看>>
ios 文件存储
查看>>
IOS 生成图片数字字母验证
查看>>
socket 使用select()非阻塞方式实现
查看>>
setsockopt()函数使用详解
查看>>
信号量sem_t,互斥锁pthread_mutex_t的使用
查看>>
FFmpeg 解码
查看>>
ffmpeg 对图像数据格式以及图片缩放
查看>>
FFmpeg编解码常用函数ffmpeg av_parser_parse2()函数
查看>>
Android 使用CMake 编译NDK
查看>>
操作系统总结
查看>>
FFmpeg 解码视频流实现yuv播放
查看>>
ffmpeg YUV420P视频帧旋转
查看>>
IOS 硬件GPU解码
查看>>
Tutk P2P的原理和常见的实现方式
查看>>
VistualStudio2017配置ffmpeg库
查看>>
ARC下用块(block)的循环引用问题样例探究
查看>>