'How can I solve "fatal: ambiguous argument 'HEAD~1': unknown revision or path not in the working tree"?
I have only one commit on master
and haven't merged it into the remote
. I want to remove my commit, keep my changed files, change my branch, and commit them.
Now I have used git reset --soft HEAD~1
, but I am faced with this error:
fatal: ambiguous argument 'HEAD~1': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git [...] -- [...]'
Solution 1:[1]
HEAD~1
is a way to point at "the parent of current commit"
In your situation: the (only) commit on master does not have a parent ...
If your intention is to have this commit on another branch, simply create that other branch:
git checkout -b my/branch
# The above is a shortcut to:
git branch my/branch # Create a new branch `my/branch` on the current commit
git checkout my/branch # Switch to this branch
With one single commit in its history, "removing the commit from master
" is the same as "deleting master
".
There is no harm in doing it (you can re-create it later): git branch -d master
, but you can also live with a local master
branch hanging around.
Solution 2:[2]
An alternative is to amend the first commit:
# Make your change in the file(s)
git add file_changes
git commit --amend --no-edit
Solution 3:[3]
If this is from flutter, then the problem is simply from your installation process. check your .git > refs , if the heads & remote directories are empty, then you simply have incomplete files. Delete your current flutter folder and download again. Ensure that 100% of the files are moved/copied during extraction
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Peter Mortensen |
Solution 2 | Peter Mortensen |
Solution 3 | David Oqua |