How do you move a commit to the staging area in git?
Solution 1:
git reset --soft HEAD^
This will reset your index to HEAD^
(the previous commit) but leave your changes in the staging area.
There are some handy diagrams in the git-reset
docs
If you are on Windows you might need to use this format:
git reset --soft HEAD~1
Solution 2:
A Simple Way
-
Committed files to Staging Area
git reset --soft HEAD^1
-
Staging to UnStage :(use "git reset HEAD ..." to unstage)
git reset HEAD git commands.txt or git reset HEAD *ds.txt
here, *--> all files end with ds.txt to unstage.
Refer the below pic for clarity:
Solution 3:
To move a commit back to the staging area depends on your last commit. If your last commit was the first(or initial) commit of the repo, then you need to execute
git update-ref -d HEAD
If your last commit is not the first(or initial) commit, then execute
git reset HEAD~