简体   繁体   中英

Git branching & local changes

We cannot switch branches in Git without committing the changes or stashing them. What is the bigger picture behind this and why did Linus take this approach while designing Git?

If switching branches cause local changes showing up across branches, What is the point in branches as they are expected work in isolation ?

We cannot switch branches in Git without committing the changes or stashing them.

Actually you can force switching branch, but then you lose any uncommitted changes on current branch. It should be very unusual if you want to lose your current work just to switching branch. Why not commit it first to current branch, or at least stash the changes so you can come back?

Anyway to force switching branch, you can:

1)

git checkout -f <new_branch>  // will lose any uncommitted changes on <old_branch>

or,

2)

git reset --hard <commit-hash-id-of-new-branch>  // will lose any uncommitted changes on <old_branch>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM