首页 > 解决方案 > git checkout 说文件没有提交,但它们是吗?

问题描述

(project_venv) jojo@jojo-System-Product-Name:~/project_fresh/examples/relational_preloadstack1/relational_stack1-layernormordertest-pkl$ git commit -m 'Huh'
On branch refactoringNormalizerIntoPreprocessingFnx
Changes not staged for commit:
        modified:   ../current_preload_relationalstack1_to_relationalstackn/preload_stack2_relational.py
        modified:   ../current_preload_relationalstack1_to_relationalstackn/resume_training_with_new_env.py
        modified:   ../current_preload_relationalstack1_to_relationalstackn/trace.html
        modified:   ../timing_test.py
        modified:   ../../../project/torch/core.py
        modified:   ../../../project/torch/sac/twin_sac.py
        modified:   ../../../scripts/convert_gpu_model_to_gpu.py
        modified:   ../../../scripts/download_s3.py
        modified:   ../../../scripts/inspect_hd5.ipynb
        modified:   ../../../scripts/sim_goal_conditioned_policy.py

no changes added to commit
(project_venv) jojo@jojo-System-Product-Name:~/project_fresh/examples/relational_preloadstack1/relational_stack1-layernormordertest-pkl$ git checkout master
error: Your local changes to the following files would be overwritten by checkout:
        examples/relational_preloadstack1/current_preload_relationalstack1_to_relationalstackn/preload_stack2_relational.py
        examples/relational_preloadstack1/current_preload_relationalstack1_to_relationalstackn/resume_training_with_new_env.py
        examples/relational_preloadstack1/current_preload_relationalstack1_to_relationalstackn/trace.html
        examples/relational_preloadstack1/timing_test.py
        project/torch/core.py
        project/torch/sac/twin_sac.py
        scripts/convert_gpu_model_to_gpu.py
        scripts/download_s3.py
        scripts/inspect_hd5.ipynb
        scripts/sim_goal_conditioned_policy.py
Please commit your changes or stash them before you switch branches.
Aborting

为什么尝试签出主分支会在此处给出“请提交更改...”错误?你可以从前面的命令中看到我已经添加并提交了所有更改到“refactoringNormalizerIntoPreprocessingFnx”分支

标签: git

解决方案


您正在尝试提交更改而不告诉 git哪些文件用于提交。

在创建提交之前(使用git commit -m "Huh"),您需要git add包含要包含的相关文件。

例如,要将单个文件添加到更改中,您可以执行以下操作:

git add ../current_preload_relationalstack1_to_relationalstackn/preload_stack2_relational.py

如果您只想添加所有已更改的文件,您可以这样做(从项目的根文件夹):

git add .

请注意,这也会将“未跟踪”文件添加到您的提交中 - 这意味着过去不受 git 控制的文件。

添加文件后,您可以git status再次运行,您将看到“暂存以供提交”的文件列表。一旦你有了这个,你可以添加你的提交:

git commit -m "Huh"

现在,当您执行时,git status您应该会看到“nothing to commit”消息。


推荐阅读