简体   繁体   中英

How can i remove detached commits from git?

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.

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 eg 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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM