简体   繁体   English

如何在git上添加补丁提交?

[英]How to add patch commit on git?

I do some commit on my local. 我在本地做了一些承诺。 but after that I realised I forget to add some files in my first commit so I use git reset --hard HEAD~4 many times likes HEAD~3 and ~1. 但是在那之后我意识到我忘了在第一次提交中添加一些文件,所以我多次使用git reset --hard HEAD~4像HEAD〜3和〜1。

After that when I check my git status its look like 之后,当我检查我的git status它看起来像

0001-basic-info-change-from-Bizkoot-to-CogitoHub.patch
0002-change-in-admin-URL.patch
0003-change-password-of-DB.patch

and in my Gitk its not showing branches like before. 在我的Gitk中,它没有像以前那样显示分支。

I just want to Commit it like before they are showing in my Gitk. 我只想像它们在我的Gitk中展示之前一样提交它。 and all branches are show like before. 并且所有分支都像以前一样显示。

git reset --hard removes all commits back to the point you specify, in this case HEAD~4 , and it also removes any changes you made in those commits. git reset --hard将所有提交还原到您指定的位置,在本例中为HEAD~4并且还删除您在这些提交中所做的任何更改。 It's basically throwing away all the work. 它基本上是在扔掉所有工作。
Sometimes it's very useful, but in this case it was not, so use it with care! 有时它非常有用,但在这种情况下却没有用,所以请谨慎使用!

What you should do instead in order to modify an older commit, is explained in this post How to modify a specified commit in git? 这篇文章中介绍了如何修改较早的提交,而应该怎么做?如何在git中修改指定的提交?

Since you did a hard reset, you will need to fix that first. 由于您进行了硬重置,因此您需要先进行修复。 In most cases you can 'undo' the reset. 在大多数情况下,您可以“撤消”重置。 See How can I undo git reset --hard HEAD~1? 请参阅如何撤消git reset --hard HEAD〜1? for how to do that. 对于如何做到这一点。 Basically to undo a reset, is to reset to a point in history before you did the reset. 基本上撤消重设,就是重设到执行重设之前的历史点。

You can try to resurrect old commits with git reflog . 您可以尝试使用git reflog恢复旧的提交。

Say you have this output: 假设您有以下输出:

$ git reflog
a0423b1 HEAD@{0}: reset: moving to HEAD~
8bba878 HEAD@{1}: commit: commit 2
a0423b1 HEAD@{2}: commit (initial): commit 1

you can get the second commit via git checkout HEAD@{1} . 您可以通过git checkout HEAD@{1}获得第二个提交。

What you really wanted was to create a new brach at HEAD~4, add your files and than merge back (or rebase) this work into master. 您真正想要的是在HEAD〜4处创建一个新分支,添加文件,然后将该工作合并(或变基)为master。

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

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