英文:
removing untracked change from git
问题
我会感激如果你能帮助我解决我在git中遇到的问题。我对使用git还很陌生。我需要移除git中的未跟踪更改。我已经尝试过"git checkout ."和"git restore .",但它们并不总是有效。是否有更可靠的方法?任何帮助都将不胜感激。
这是我需要从git中移除的未跟踪文件:
Untracked files:
(use "git add <file>..." to include in what will be committed)
secret1.txt
test-repo % git restore .
test-repo % git status
HEAD detached from V2
Untracked files:
(use "git add <file>..." to include in what will be committed)
secret1.txt
test-repo % git checkout .
Updated 0 paths from the index
test-repo % git status
HEAD detached from V2
Untracked files:
(use "git add <file>..." to include in what will be committed)
secret1.txt
nothing added to commit but untracked files present (use "git add" to track)
正如你所看到的,secret1.txt 仍然存在!
英文:
I would appreciate if you help me in this problem I have with git. I am new with working with that. I need to remove untracked change from git. I have already tried "git checkout ." and " git restore .", but those are not working always. Is there any more reliable way? Any help is appreciated.
This is the untracked file I need to be removed from git:
Untracked files:
(use "git add <file>..." to include in what will be committed)
secret1.txt
test-repo % git restore .
test-repo % git status
HEAD detached from V2
Untracked files:
(use "git add <file>..." to include in what will be committed)
secret1.txt
test-repo % git checkout .
Updated 0 paths from the index
test-repo % git status
HEAD detached from V2
Untracked files:
(use "git add <file>..." to include in what will be committed)
secret1.txt
nothing added to commit but untracked files present (use "git add" to track)
As you can see secret1.txt is still there!
答案1
得分: 2
Git命令:
git clean -f
(移除所有未跟踪的文件)git clean -f path/to/file
(移除特定文件 path/to/file)
英文:
Git commands:
git clean -f
(remove all untracked files)git clean -f path/to/file
(remove the specific file path/to/file)
答案2
得分: 0
"untracked changes" 是指 Git 完全不了解的文件。解决这个问题的最简单方式就是使用 rm secret1.txt
命令删除该文件。
英文:
"untracked changes" are by definition files which git knows nothing about. The easiest way to fix this is just to delete the file with rm secret1.txt
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论