我的本地工作区太乱了,如何一一清理后,再push到我的仓库?

请看本地的状态:

git status
On branch master
You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Changes to be committed:
    new file:   source/github/找出删除的文件.rst
    deleted:    source/os/白名单.rst

Unmerged paths:
  (use "git add <file>..." to mark resolution)
    both modified:   other/.bashrc

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    modified:   source/os/上网设置.rst

Untracked files:
  (use "git add <file>..." to include in what will be committed)
    source/github/git命令行正确显示中文.rst

各种状态的文件都有
1.如何处理Changes to be committed:

new file:   source/github/找出删除的文件.rst
deleted:    source/os/白名单.rst

这两个文件,如何处理?

2.如何处理Unmerged paths:
(use "git add <file>..." to mark resolution)

both modified:   other/.bashrc

按照提示了 git add

3.如何处理Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)

modified:   source/os/上网设置.rst

这个我也git add

4.如何处理Untracked files:
(use "git add <file>..." to include in what will be committed)

source/github/git命令行正确显示中文.rst

这个我也git add

后面几个情况,根据提示来做,那这两个文件呢?

new file:   source/github/找出删除的文件.rst
deleted:    source/os/白名单.rst

source/github/找出删除的文件.rst是新文件,可以不管吧,下次push就好。
那个折腾半天的"source/os/白名单.rst",还是不好解决!
我可以通过
git checkout 424a74fba6fbf6ad53e59e7d579427b7acdfde -- source/os/白名单.rst
总结我经历过的混乱(搞好后,再写笔记了,本地的工作区先冻结了):
恢复了这个文件后,我不能git push,否则报错,系统提示,必须git pull,如果我git pull,那么这个文件就又会丢失!!

阅读 2k
1 个回答

Changes to be committed:文件已经被添加到了暂存区,准备进行提交。你用 git commit -m "Add deleted file and remove white list"。

Unmerged paths:这些文件在合并过程中产生了冲突,要你手动解决。你要打开文件,找到冲突的(一般有这样的标记 <<<<<<, ======, >>>>>> ),然后看你要保留哪些更改。解决冲突之后后,用 git add <file> 这样就解决了冲突。然后可以提交代码了。

总结一下,你要先解决所有的冲突,然后git add .加到暂存区,最后进行提交git commit -m "Add deleted file and remove white list"。这样你的工作区就会变干净,然后你就可以推送git push操作了

logo
Microsoft
子站问答
访问
宣传栏