我在使用git时遇到了一些问题,它无法正常保存一些更改并且它已经制作了2份副本。我删除了副本,然后我使用了命令git checkout -- fileName
,现在文件已存在,我可以在IDE中看到它,但它是空的。
诀窍是 - 我没有提交。所以..在服务器上文件已经准备就绪,但在我的本地机器上却没有。当我尝试将代码从服务器复制并粘贴到我的本地文件中时,我收到错误"没有这样的文件或目录存在"即使它在我的IDE中可见,它也无法保存更改(PHPStorm)。
这是我实际做过的控制台
➜ myProject(myBranch) ✗ git status
On branch myBranch
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: assets/src/js/header.js
Untracked files:
(use "git add <file>..." to include in what will be committed)
assets/src/js/header.js___jb_old___
assets/src/js/header.js___jb_tmp___
no changes added to commit (use "git add" and/or "git commit -a")
➜ myProject git:(myBranch) ✗ rm assets/src/js/header.js___jb_old___
➜ myProject git:(myBranch) ✗ git status
On branch myBranch
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: assets/src/js/header.js
Untracked files:
(use "git add <file>..." to include in what will be committed)
assets/src/js/header.js___jb_tmp___
no changes added to commit (use "git add" and/or "git commit -a")
➜ myProject git:(myBranch) ✗ rm assets/src/js/header.js___jb_tmp___
➜ MyProject git:(myBranch) ✗ git status
On branch myBranch
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: assets/src/js/header.js
no changes added to commit (use "git add" and/or "git commit -a")
➜ myProject git:(myBranch) ✗ git diff assets/src/js/header.js
➜ myProject git:(myBranch) ✗ git checkout -- assets/src/js/header.js
➜ myProject git:(myBranch) git status
On branch myBranch
nothing to commit, working directory clean
正如你所看到的,我有一个由git制作的两个副本的文件。然后我删除了副本并使用git checkout尝试恢复所有更改。
目前该文件为空,即使我还没有做过任何提交。我没有提交任何东西
我只是想让我的文件按原样出现,并且当前正在服务器上。
[编辑] - 我试过git reset HEAD assets/src/js/header.js
但没有任何反应。我知道该文件在服务器上,但我不能使我的本地副本与服务器上的相同。
[编辑] - 我也尝试在不同的分支之间切换,文件仍为空,并且没有提交更改。