如果您想将提交移至暂存区域 - 即取消提交并将其中的所有更改移至暂存区域(有效地将分支置于提交之前的状态)-你怎么做的?或者这是你做不到的事情?
我知道如何做的最接近的是将提交中更改的所有文件复制到其他地方,将分支重置为您尝试移入暂存区域的提交之前的提交,移动所有将文件复制回存储库,然后将它们添加到暂存区域。它确实有效,但并不是一个很好的解决方案。我想要做的只是撤消提交并将其更改移至暂存区域。能做到吗?如果是这样,怎么办?
If you want to move a commit to the staging area - that is uncommit it and move all of the changes which were in it into the staging area (effectively putting the branch in the state that it would have been in prior to the commit) - how do you do it? Or is it something that you can't do?
The closest that I know how to do is to copy all of the files that were changed in the commit to somewhere else, reset the branch to the commit before the commit that you're trying to move into the staging area, move all of the copied files back into the repository, and then add them to the staging area. It works, but it's not exactly a nice solution. What I'd like to be able to do is just undo the commit and move its changing into the staging area. Can it be done? And if so, how?
发布评论
评论(3)
这会将您的索引重置为
HEAD^
(之前的提交),但将更改保留在暂存区域中。方便的图表 -scm.com/docs/git-reset" rel="noreferrer">
git-reset
docs如果您使用的是 Windows,则可能需要使用以下格式:
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
docsIf you are on Windows you might need to use this format:
一种简单的方法
将文件提交到暂存区
git reset --soft HEAD^1
git重置HEAD git命令.txt
或 git reset HEAD *ds.txt
,
*-->所有以 ds.txt 结尾的文件都需要取消暂存。
为了清楚起见,请参阅下图:
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:
将提交移回暂存区域取决于您的最后一次提交。
如果您的最后一次提交是存储库的第一次(或初始)提交,那么您需要执行
如果您的最后一次提交不是第一次(或初始)提交,则执行
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
If your last commit is not the first(or initial) commit, then execute