I have two detached commits. How can i remove they as if they had never been? I don't want save history or another logs. Nothing.
Asked
Active
Viewed 1.5k times
2 Answers
13
Do you mean commits made while you had a detached HEAD? If so, just:
git checkout some_branch
Your commits will no longer be visible in e.g. git log
. They will be culled from storage at some point while Git runs its garbage-collection sweeps. If you want to cull things now, see answers to this question: How to remove unreferenced blobs from my git repo.

Community
- 1
- 1

Oliver Charlesworth
- 267,707
- 33
- 569
- 680
-
After following those steps, I can still checkout the commit id of the commit I made while on a detached HEAD. Git version 1.8.3.4 – whaley Dec 18 '13 at 18:54
-
1@whaley: You're right, the default `git gc` isn't aggressive enough. Answer updated. – Oliver Charlesworth Dec 18 '13 at 18:56
-
-
2So, this is an unanswered question yet?. It is misleading to see the green accepted check mark. – jgomo3 Sep 15 '15 at 14:07
-
Having `git version 2.18.0`. Detached commit had disappeared immediately after I've got rid of stash, which has been made while being on a detached commit. – Cryptor Aug 03 '18 at 20:05
0
For me it worked to delete the local master
branch with
git branch -D master
then I need to recreate it after moving to the right point/commit
git checkout -b master
Then I published
to remote, for some reason the track between origin/master and the local master still exists, and I found on remote repo only a clean commit.
Just to give an idea, this was my starting point:
* 08c6d59 (tmp) add MStatus to key to compare. rif. #1858
| * 1f78459 (master) Merge branch 'master' of ssh://xxxxxxxxx:10022/xWave/csv_import_tool
| |\
| |/
|/|
| * d190a9f field_mapping replace field_map. rif. #1725
| | * 3e2a843 (quickfix-1858) is_the_same_as_dbrow false if import has repricing update. rif. #1858
| |/
|/|
* | 5e3a9b8 (HEAD, origin/master) field_mapping replace field_map. rif. #1725
|/
* 7b4a700 field map to aufbau+platform attributes. rif. #1725
* 4a174f7 set timeout of 12 seconds, then exits parse_csv_lines. rif. #1836
* b73df93 json encode error message in all cases. rif. #1836
* 8d80459 include platform attribute to map of fields. rif. #1801 step 1
* 331244f add mstatus and quantity options. rif. #1698 #1675
* 4dd3c48 move in unused the unused files
* 3326ff5 change the right file
After the change:
* 08c6d59 (HEAD -> master, origin/master, tmp) add MStatus to key to compare. rif. #1858
| * 3e2a843 (quickfix-1858) is_the_same_as_dbrow false if import has repricing update. rif. #1858
|/
* 5e3a9b8 field_mapping replace field_map. rif. #1725
* 7b4a700 field map to aufbau+platform attributes. rif. #1725
* 4a174f7 set timeout of 12 seconds, then exits parse_csv_lines. rif. #1836
reflog
08c6d59 (HEAD -> master, origin/master, tmp) HEAD@{0}: checkout: moving from 08c6d59c0d8e9a8ea58c850f092f1a8800857574 to master
08c6d59 (HEAD -> master, origin/master, tmp) HEAD@{1}: merge tmp: Fast-forward
5e3a9b8 HEAD@{2}: checkout: moving from tmp to origin/master
08c6d59 (HEAD -> master, origin/master, tmp) HEAD@{3}: commit: add MStatus to key to compare. rif. #1858
5e3a9b8 HEAD@{4}: checkout: moving from master to tmp
1f78459 HEAD@{5}: checkout: moving from 5e3a9b893a31674610d52e505830f94c4e96409e to master
5e3a9b8 HEAD@{6}: checkout: moving from master to 5e3a9b8
1f78459 HEAD@{7}: pull origin master: Merge made by the 'recursive' strategy.
d190a9f HEAD@{8}: commit: field_mapping replace field_map. rif. #1725
7b4a700 HEAD@{9}: reset: moving to HEAD~
5e3a9b8 HEAD@{10}: checkout: moving from quickfix-1858 to master
3e2a843 (quickfix-1858) HEAD@{11}: commit: is_the_same_as_dbrow false if import has repricing update. rif. #1858

Daniele Cruciani
- 623
- 1
- 8
- 15