在签出不同的分支时,在git中删除未分级的,未提交的文件

问题描述 投票:1回答:1

我删除了特定分支的本地和远程分支

git branch -d branchName
git branch --delete --remotes origin/branchName

当我结帐不同的分支时,当我运行git status时,我仍然看到未跟踪/未提交的文件。

这些文件没有我想要保留或暂存或提交的任何更改。当我在不同的分支上运行git status时,我不想看到他们坐在该区域

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:   ../../../../path/to/folder/file.html
    modified:   ../../../../path/to/folder/file.js

当我在任何一个分支上运行git status时,我想看到这个

On branch proj/branch/#
Your branch is up to date with 'origin/proj/branch/#'.

nothing to commit, working tree clean

有没有办法做到这一点,如果是这样,那怎么办?

git git-commit unstage
1个回答
1
投票

通常,要撤消所有文件的更改并将其还原到上次提交状态,您需要执行以下操作:

git reset --hard

(这里暗示HEAD)(doc

但是警告:这不可撤消。

你也可以只是git stash,这也可以摆脱变化,但如果你想稍后让他们回来或只是检查它们,你将能够,用一个简单的git stash show <stashRef>,或与git apply <stashRef>,其中<stashRef>git stash list一起被发现。


要回答你关于藏匿的评论,如果你发现了什么并且不再需要它,你有两种清理旧藏匿条目的方法:

# global
git stash clear

# or specific
git stash drop <entryRef>

(通过<entryRef>找到git stash list

© www.soinside.com 2019 - 2024. All rights reserved.