If i was on my local branch, used git add -A
to add all changes to the staging area, but without committing, and then checked out to a remote branch. Is there any way to get back to what was on my local staging area?
Asked
Active
Viewed 36 times
-1

jonrsharpe
- 115,751
- 26
- 228
- 437

Klaxon
- 53
- 4
-
Do the changes still exist in the staging area? – evolutionxbox May 01 '21 at 22:26
-
when i run "git status" on my local branch, it says working tree clean, so i guess not – Klaxon May 01 '21 at 22:34
-
If the changes are not in the staging area then no. The changes are gone. They're not in the staging area and have not been committed. Double-check your text editor to see if the changes still exist there? "working tree clean" doesn't mean they're not there though. – evolutionxbox May 01 '21 at 22:35
-
Note that if you have a bunch of staged files that differ from the committed files, `git checkout` will often refuse to check out the other branch. If it *allows* the checkout, the other branch has "the same versions" of those files. See [Checkout another branch when there are uncommitted changes on the current branch](https://stackoverflow.com/q/22053757/1256452). As my long answer notes, this can sometimes lose the fact that stuff was staged, although as long as you didn't *force* the checkout, the content *is* somewhere in some commit(s). – torek May 02 '21 at 05:22
1 Answers
0
Git traffics only in commits. As a rule, whatever is not committed can be lost.
Switching branches generally overwrites the staging area. It also generally overwrites the working area, so switching branches without committing first is usually frowned on.
But if you modified files in the work area and switched branches without committing, then if Git permitted that, those files are still in the work area and you can just add them. Git won’t overwrite uncommitted changes unless you tell it to.

matt
- 515,959
- 87
- 875
- 1,141