Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git reset --soft HEAD^ for initial commit

Tags:

git

Could someone please tell me what would be an equivalent of git reset --soft HEAD^ for an initial commit? I'm trying to find a really safe one-liner without any deletions :)

To further clarify: I want all the files I tediously added to be in the index and ready for committing after the command is run.

like image 878
nzn Avatar asked Oct 07 '18 08:10

nzn


People also ask

Is git reset soft by default?

git reset --soft , which will keep your files, and stage all changes back automatically. git reset --hard , which will completely destroy any changes and remove them from the local directory. Only use this if you know what you're doing.

What does git reset soft head do?

When using git reset --soft HEAD~1 you will remove the last commit from the current branch, but the file changes will stay in your working tree. Also the changes will stay on your index, so following with a git commit will create a commit with the exact same changes as the commit you "removed" before.


1 Answers

As you found, for the initial commit using git reset --soft HEAD^ doesn't work.

What does work is using git update-ref -d HEAD.

But provided that there is only one branch and one commit, it's can be easier to just delete the .git directory and start over. Of course, you should only do that if you know what you are doing.

like image 114
Fake Code Monkey Rashid Avatar answered Sep 23 '22 00:09

Fake Code Monkey Rashid