Skip to main content
32 events
when toggle format what by license comment
Apr 21, 2021 at 5:04 comment added swarnava112 I did git checkout master then I got warned that two commits are attached to no branch so I did git checkout <new-branch> <latest-of-the-two-commits> and then git merge <new-branch>. And that did the trick
Oct 9, 2019 at 8:45 comment added R Reveley As someone who has to use basic git functions on a daily basis but doesn't really know what they are doing, I find taking a copy when things start to get cocked up saves a lot of tears. That way if/when your work gets lost into the ether you can always resort to cherry picking your work out and recommitting it as if you'd just created it.
May 16, 2019 at 8:23 comment added Lee Maan @Archonic Yep, this answer just destroyed my work. But it helped me too since I made a backup when I sensed the risk. Thanks Daniel Alexiuc!
Mar 21, 2019 at 11:36 comment added sfy When you are working submodules, you probably lost all the new commits just pulled.
Mar 11, 2019 at 16:15 comment added Yusufali2205 Agree with @Archonic It is important to understand how git works before you blindly run any commands. You can save time by not reading the big answer, but can lose more time if your work is lost.
Oct 22, 2018 at 5:19 comment added user7659542 I tried git checkout origin/master, but that didn't work. How is this different from git checkout master? And why does this work?
Feb 19, 2017 at 5:18 comment added norixxx isn't git checkout -B master dangerous? Because it basically resets master branch (or whatever existing branch) and discard all commits made before revert, unless they know what they are doing.
Jan 25, 2017 at 0:12 history rollback Daniel Alexiuc
Rollback to Revision 14
Jan 17, 2017 at 5:07 history edited Sudhanshu Mishra CC BY-SA 3.0
Added command to remove temp branch
Aug 31, 2016 at 6:12 history edited Daniel Alexiuc CC BY-SA 3.0
an equivalent, but shorter, command
Jun 13, 2016 at 1:26 comment added Opus1217 git reset should come with a warning "If you have no idea what you're doing, stop it". Just recovered from an hour of terror thinking I'd lost the last week of work. Thanks!
Jun 13, 2016 at 1:12 comment added Daniel Alexiuc @Blauhirn You probably had the commit checked out, not the branch. The branch still points to the same commit, but you're in a different 'mode'.
Jun 12, 2016 at 2:14 comment added phil294 I don't understand this. git checkout master solved it, but why? My HEAD was ALREADY at the latest master commit. The HEAD didnt change after this command. Why was a checkout needed then?
Mar 29, 2016 at 2:30 history edited Daniel Alexiuc CC BY-SA 3.0
improved grammar
Mar 29, 2016 at 2:22 history edited Daniel Alexiuc CC BY-SA 3.0
Explain how to keep changes.
Mar 28, 2016 at 20:53 comment added Tony !"git checkout master" will cause all changes to be lost if the detached head is not part of master !!
Mar 10, 2016 at 18:51 comment added Archonic This is a dangerous response. People arriving at this answer have different states and "just do this to fix it" responses don't answer questions. This one can easily destroy work.
Jan 21, 2016 at 23:13 history rollback Daniel Alexiuc
Rollback to Revision 2
Jan 21, 2016 at 17:18 history edited Félix Adriyel Gagnon-Grenier CC BY-SA 3.0
added warning.
Jan 16, 2016 at 23:00 history rollback Daniel Alexiuc
Rollback to Revision 2
Jan 15, 2016 at 10:30 history edited Cees Timmerman CC BY-SA 3.0
document and explain dangerous command
Nov 16, 2015 at 23:27 review Suggested edits
Nov 17, 2015 at 0:31
Oct 8, 2015 at 1:21 history rollback Daniel Alexiuc
Rollback to Revision 2
Oct 8, 2015 at 1:17 history rollback Daniel Alexiuc
Rollback to Revision 3
S Oct 7, 2015 at 15:24 history edited kenorb CC BY-SA 3.0
missing information
S Oct 7, 2015 at 15:24 history suggested Tin Nguyen CC BY-SA 3.0
missing information
Oct 7, 2015 at 14:23 review Suggested edits
S Oct 7, 2015 at 15:24
S Dec 12, 2014 at 22:15 history suggested Tejas Sharma CC BY-SA 3.0
grammar (also I accidently downvoted this answer and can't upvote it)
Dec 12, 2014 at 21:18 review Suggested edits
S Dec 12, 2014 at 22:15
Oct 18, 2013 at 1:34 history edited Daniel Alexiuc CC BY-SA 3.0
added alternative case for another detached head scenario
Sep 18, 2013 at 7:41 review Low quality answers
Sep 18, 2013 at 7:47
Sep 18, 2013 at 7:23 history answered Daniel Alexiuc CC BY-SA 3.0