Home  >  Q&A  >  body text

git checkout old_branch后在new_branch更改的内容也一同更新了,该怎么办?

首先在master下创建了一个txt文件,然后git checkout -b dev创建了一个新的分支,在dev分支下更改了txt文件内容,结果直接返回master分支成功了,并且,内容也一并更新了,这是什么问题,应该怎么改?

怎样修改才会不同步呢?

仅有的幸福仅有的幸福2747 days ago557

reply all(1)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-02 09:26:34

    Did you switch back to master directly without committing under dev?
    In this case, your changes are still in the cache and do not belong to any branch. So after you switch to master, you find that the content has been updated.

    The normal process is to commit to the dev branch first, and then merge to the master.
    So you should now checkout to dev again, and then perform the above commit and merge operations.

    In fact, if your master also changes the same file, git will prompt you that you cannot switch from dev to master unless you commit first or stash the cache.

    reply
    0
  • Cancelreply