1

I have checked-out a branch (BranchA), made changes to the code.

Then I connect to different branch (BranchB) without committing code from IDE.

The changes I had made on BranchA in IDE are lost?

variable
  • 8,262
  • 9
  • 95
  • 215
  • If you have commited your changes locally in branchA before checking out they are saved. I doubt this would be an IDE specific save. You could make the change in Notepad and commit using the command line. – ste2425 Oct 07 '19 at 09:12
  • By "connect to different branch", you mean check out a different branch? – Lasse V. Karlsen Oct 07 '19 at 09:12
  • Typically the changes in your working directory would just be carried over _unless_ doing so would result in a conflict when checking out the other branch. As a general rule, you should avoid switching branches if your working directory and stage are dirty (workarounds include worktrees, stash, and a few other things). – Tim Biegeleisen Oct 07 '19 at 09:13
  • If you have made changes to files that, in your git repository, are the same between those two branches, your changes and uncommitted files will simply carry over. You will still have uncommitted changes after switching branches. If, on the other hand, the files are different in those two branches, git will refuse to switch branches because that will change your uncommitted files. – Lasse V. Karlsen Oct 07 '19 at 09:14
  • Note that you didn't really make changes **on** BranchA, you made changes to your local working folder. After switching to another branch, if that succeeds, your working folder is updated to reflect the branch you switched to + your changed files. If you now commit, that commit will be on the new branch you switched to, not on BranchA. – Lasse V. Karlsen Oct 07 '19 at 09:16
  • 2
    Possible duplicate of [git switch branch without discarding local changes](https://stackoverflow.com/questions/22082307/git-switch-branch-without-discarding-local-changes) – AElMehdi Oct 07 '19 at 09:25
  • The IDE does not matter (too much) here. This question is entirely about Git. – axiac Oct 07 '19 at 10:04

1 Answers1

1

Usually, you cannot check-out another branch if you have unsaved changes. You either commit those (i.e. everything is saved) or explicitly discard the changes (i.e. everything is lost) and only then check-out the other branch so that there is no ambiguity.

basania
  • 125
  • 1
  • 8