如何在切换分支时停止git 自动更新?

How to stop git auto-update when switching branches?

我有两个分支:

----master
  |
  |----lf

我在分支 lf 中开发了一些新功能并获得了一些输出。然后,我尝试切换回 master(通过 git checkout)并执行程序来比较结果。不幸的是,git checkout master 将更新我在 lf:

中所做的事情
M   Makefile
M   src/mainloop.c
M   src/threadpool.c
M   src/threadpool.h
Already on 'master'
Your branch is up to date with 'origin/master'.

结果,我在两个分支中得到了完全相同的项目。这不是我想要的。我不希望 master 自动更新我在 lf 中更改的内容。

我的问题是:

  1. 如何在执行分支 (git branch lf) 之前恢复 master 中的代码?

  2. 如何在没有自动更新的情况下在不同分支之间切换?

  1. How to recover the code in master before I do branch (git branch lf)?

在执行 git checkout master.

之前执行提交(例如 git commit -a -m "…"

否则,如果您不想执行 "temporary" 提交,请执行 git stash。稍后,执行 git checkout lf && git stash pop 以检索您未提交的代码。

  1. How to switch different branch with no auto up to date ?

基本上没有"auto-update":您观察到的原因只是您的工作目录不干净(即,有一些未提交的修改),并且更改分支不会自动更新任何内容, 它只是保持这些修改原样(否则会导致数据丢失!)

此外,您可能希望随时 运行 一个方便的命令,以更深入地了解 current-branch/index/working-directory is: git status.

的当前状态