
D:\JAVA\projects\syxwall-parent>git status On branch master Your branch is ahead of 'origin/master' by 1 commit. (use "git push" to publish your local commits) Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: .gitignore modified: log/backend/normal/normal.log modified: log/backend/sql/sql.log modified: log/mirai/normal/normal.log deleted: syxwall-backend/syxwall-backend-web/src/main/java/com/syxgo/syxwall/backend/web/controller/FallbackController.java modified: syxwall-mirai/syxwall-mirai-api/src/main/java/com/syxgo/syxwall/mirai/api/MiraiRobotApis.java no changes added to commit (use "git add" and/or "git commit -a") D:\JAVA\projects\syxwall-parent>git reset HEAD log/backend/normal/normal.log Unstaged changes after reset: M .gitignore M log/backend/normal/normal.log M log/backend/sql/sql.log M log/mirai/normal/normal.log D syxwall-backend/syxwall-backend-web/src/main/java/com/syxgo/syxwall/backend/web/controller/FallbackController.java M syxwall-mirai/syxwall-mirai-api/src/main/java/com/syxgo/syxwall/mirai/api/MiraiRobotApis.java normal.log 出现在 Unstaged changes after reset: 就 TM 离谱
为什么啊?
1 learningman May 5, 2021 via Android git reset HEAD --hard |
2 JasonLaw May 5, 2021 via iPhone 你可以先说一下你想实现什么,什么是“ 把一个被 add 的文件给赶出去”? |
3 JasonLaw May 5, 2021 via iPhone |
4 learningman May 5, 2021 via Android @JasonLaw 我知道啊,我平常都用 mixed,但是楼主这个操作就是要用 hard |
5 JasonLaw May 5, 2021 via iPhone @learningman #4 我的意思是“你应该说明出这个命令存在的危险性”,没有别的意思。 |
6 learningman May 5, 2021 via Android @JasonLaw 没危险的,你仍然可以 git reflog 来恢复,git 会保存一切操作 |
7 Newyorkcity OP @JasonLaw 就是我不需要这些文件被 git 管理 至于文件上的改动我希望能保留 |
8 orcusfox May 5, 2021 via iPhone 你的日志里已经贴了,要用 git checkout log/mirai/normal/normal.log |
9 JasonLaw May 5, 2021 via iPhone |
10 JasonLaw May 5, 2021 via iPhone @learningman #6 "If you accidentally remove uncommited changes which were never tracked by git (speak: committed or at least added to the index), you have no way of getting them back using git.",那怎么解释这段话呢? |
11 Newyorkcity OP @napsterwu 那这样修改的内容不就保存不了了? |
12 yuancoder May 5, 2021 Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) 已经提示的很明白了 |
13 jokerai May 5, 2021 “不需要 git 管理 / 把文件踢出 git 管辖区 / 让 git 无视这个文件的存在吧” 的设置是应该放在 .gitignore 里的 如果误操作了,则先更新 .gitignore 文件并 commit,再对此文件把它移出去、commit 一次、再把它移回来就 OK 参考 https://stackoverflow.com/questions/1274057/how-to-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore/1274081#1274081 例子 cd testDir1 git init touch 1.txt 2.txt 3.txt 4.txt 5.txt git add 1.txt 2.txt git commit -m 'update' touch .gitignore nano .gitignore 写入 2.txt git commit -m 'update gitignore' 把 2.txt 移到外面目录( git 管辖区文件夹的外面) git add 2.txt git commit -m 'update' 把 2.txt 移到目录( git 管辖区文件夹) git status 此后 2.txt 不会再被 git 管辖 |
14 jokerai May 5, 2021 上面少了一步, 应该是 touch .gitignore nano .gitignore 写入 2.txt git add .gitignore git commit -m 'update gitignore' |
15 yuhaoyuhao May 5, 2021 no changes added to commit (use "git add" and/or "git commit -a") |
16 msg7086 May 6, 2021 你先要搞清楚状况。 1. log 文件已经在仓库里了,不管你做什么操作,他们都在仓库里。之前已经有人把这几个文件提交进去了,换句话说这些文件已经成了历史书的一部分,你只有改变历史才能「踢出」这个文件。 2. Unstaged changes 的部分是不会进入提交的(除非你提交时手动要求加入 unstaged )。所以这些文件在 Unstaged 里是再正常不过了。 |
17 fyy21 May 6, 2021 git reset HEAD~ |
18 Delbert May 6, 2021 git update-index --assume-unchanged <file> 这个? |