Timeline for How do I undo 'git add' before commit?
Current License: CC BY-SA 4.0
16 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Oct 27, 2022 at 13:45 | comment | added | Filip Savic | Ohh! Overwritten in the index, not in the file itself :D Alright, thank you! | |
Oct 26, 2022 at 18:46 | comment | added | iolsmit |
@FilipSavic If you add the same file multiple times, without committing. E.g. echo 1 > a.txt followed by git add a.txt - do not commit yet - echo 2 > a.txt followed by git add a.txt ; now commit e.g. git commit -m "create unreachable blob" and run git fsck --unreachable
|
|
Oct 25, 2022 at 13:17 | comment | added | Filip Savic |
@iolsmit How can a git add overwrite a change that was staged but not committed? If I created a file a.txt and it had '1' as it's content, how can git add make it have '2' or sth else as it's content? Just looking for an explanation
|
|
Nov 3, 2019 at 13:21 | history | edited | Peter Mortensen | CC BY-SA 4.0 |
Active reading [<https://en.wikipedia.org/wiki/Sentence_clause_structure#Run-on_(fused)_sentences> <https://en.wiktionary.org/wiki/upvote> <https://en.wikipedia.org/wiki/Git> <https://en.wiktionary.org/wiki/committed#Verb>].
|
Oct 15, 2018 at 17:23 | history | edited | leonbloy | CC BY-SA 4.0 |
added 263 characters in body
|
Apr 27, 2018 at 15:29 | comment | added | iolsmit |
Another way to recover changes that were staged but not committed and then overwritten by e.g. another git add is via git fsck --unreachable that will list all unreachable obj, which you can then inspect by git show SHA-1_ID or git fsck --lost-found that will >Write dangling objects into .git/lost-found/commit/ or .git/lost-found/other/ , depending on type. See also git fsck --help
|
|
Dec 6, 2017 at 13:22 | comment | added | Johannes Matokic |
To correct myself: Once the loose object file is found (use meta-data like creation date/time) git cat-file could be used to recover its content.
|
|
Dec 6, 2017 at 13:07 | comment | added | Johannes Matokic | Strictly speaking there is a way to recover an already staged file that was replaced with git add. As you mention git add creates an git object for that file that will become a loose object not only when removing the file completely but also when being overwritten with new content. But there is no command to automatically recover it. Instead the file has to be identified and extracted manually or with tools written only for this case (libgit2 will allow this). But this will only pay out if the file is very important and big and could not be rebuild by editing the previous version. | |
S Jul 27, 2015 at 17:19 | history | suggested | will.fiset | CC BY-SA 3.0 |
Spelling error
|
Jul 27, 2015 at 17:06 | review | Suggested edits | |||
S Jul 27, 2015 at 17:19 | |||||
Apr 8, 2015 at 19:59 | history | edited | leonbloy | CC BY-SA 3.0 |
deleted 4 characters in body
|
Jan 30, 2014 at 18:59 | history | edited | leonbloy | CC BY-SA 3.0 |
added 31 characters in body
|
Jul 1, 2013 at 20:29 | history | edited | leonbloy | CC BY-SA 3.0 |
added 100 characters in body
|
May 7, 2013 at 12:16 | history | edited | leonbloy | CC BY-SA 3.0 |
added 19 characters in body
|
May 6, 2013 at 19:06 | history | edited | leonbloy | CC BY-SA 3.0 |
added clarification to answer to the main question
|
May 18, 2011 at 18:05 | history | answered | leonbloy | CC BY-SA 3.0 |