0

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.

After that when I check my git status its look like

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.

I just want to Commit it like before they are showing in my Gitk. and all branches are show like before.

Tim
  • 41,901
  • 18
  • 127
  • 145
abhi-axis
  • 149
  • 1
  • 12

2 Answers2

0

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

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? for how to do that. Basically to undo a reset, is to reset to a point in history before you did the reset.

Community
  • 1
  • 1
Tim
  • 41,901
  • 18
  • 127
  • 145
0

You can try to resurrect old commits with 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}.

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.

Rudi
  • 19,366
  • 3
  • 55
  • 77