Git: can't switch between branches

前端 未结 3 1639
眼角桃花
眼角桃花 2021-01-17 03:53

In a local folder with several files, I have a git repository for which branch x only includes a few of those files, and the master one inc

相关标签:
3条回答
  • 2021-01-17 04:06

    git checkout -f branch_you_want_to_go

    CAREFUL. This will revert ALL changes done on the branch. But if you are forced to merge and doesnt let you stash is an easy way when not much is done.

    Do this if you want to delete your branch afterwards (probably with git branch -D branch_to_delete) or you want to start working on this brand from 0.

    0 讨论(0)
  • 2021-01-17 04:12

    You have some files (the ones listed) that have been edited, but by checking out a other branch, you'll overwrite (and lose) these edits.

    You can commit these changes, or stash them.

    See : http://git-scm.com/book/en/v1/Git-Tools-Stashing

    0 讨论(0)
  • 2021-01-17 04:20

    The problem is that you have files that have not been added to the working tree (Eg: new files created after the last commit). Git is preventing you from losing those files when you want to switch branches.

    In order to be able to change the branch, you can either add those files to the working tree (git add file1.out or for all: git add --all) or you can remove them (git rm file1.out ...). Then you can either commit or (if not ready) you can stash them (git stash) and when you want them back (git stash pop)

    More info here and here.

    0 讨论(0)
提交回复
热议问题