简体   繁体   English

如何从 git 中删除分离的提交?

[英]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?你的意思是在你有一个独立的 HEAD 时提交的? If so, just:如果是这样,只需:

git checkout some_branch

Your commits will no longer be visible in eg git log .您的提交将不再在例如git log可见。 They will be culled from storage at some point while Git runs its garbage-collection sweeps.当 Git 运行其垃圾收集扫描时,它们将在某个时候从存储中剔除。 If you want to cull things now, see answers to this question: How to remove unreferenced blobs from my git repo .如果你现在想剔除一些东西,请参阅这个问题的答案: 如何从我的 git repo 中删除未引用的 blob

For me it worked to delete the local master branch with对我来说,它可以删除本地master分支

git branch -D master git 分支 -D 主

then I need to recreate it after moving to the right point/commit然后我需要在移动到正确的点/提交后重新创建它

git checkout -b master 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.然后我published到远程,出于某种原因,origin/master 和本地 master 之间的轨道仍然存在,我在远程 repo 上发现只有一个干净的提交。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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