我使用 git reset --soft HEAD^ 来保存我的状态,然后提交。那么是不是每次,如果我想提交,我应该使用 git reset --soft HEAD^ ?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11237620/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
I used git reset --soft HEAD^ to hold my state, then did commit. So is it like each time, if I want to commit, I should use git reset --soft HEAD^ ?
提问by Rohan Nemaro
Actually I was not sure so, I followed git amend approach everytime. Is it good practice ? If not Why git amend is not good ?
实际上我不确定,我每次都遵循 git amend 方法。这是好的做法吗?如果不是为什么 git amend 不好?
回答by meagar
No, using git commit --amend
is nota good practice "every time". It merges your current changes with the previous commit's changes. You'll wind up with a single massive commit and no commit history what so ever. You should be making lots of small, granular changes so that you can actually track the evolution of features and introduction of bugs.
不,使用git commit --amend
是不是一个好的做法“每次”。它将您当前的更改与先前提交的更改合并。你会得到一个单一的大规模提交,而没有任何提交历史。您应该进行大量细小的更改,以便您可以实际跟踪功能的演变和错误的引入。
Using git reset --soft HEAD^
is more or less identical in effect: You're moving the branch pointer to the previous commit but leaving the working directory state unchanged, then making a single large commit with all the changes you've introduced.
使用的git reset --soft HEAD^
效果或多或少相同:您将分支指针移动到前一个提交,但保持工作目录状态不变,然后使用您引入的所有更改进行单个大型提交。
Using either command every time you commit will leave you with a single commit containing your entire project to date. There is absolutely no good reason to do this, and it is the completely wrong way of using version control.
每次提交时使用任一命令都会让您得到一个包含迄今为止整个项目的提交。这样做绝对没有充分的理由,这是使用版本控制的完全错误的方式。
回答by Tim Jarvis
git reset --soft HEAD^
will effectively just wind back to a state prior to your last commit, but leave your changes in the index (as if you had done a git add, but not yet a git commit)
将有效地回到您上次提交之前的状态,但将您的更改保留在索引中(就像您已经完成了 git add,但还没有进行 git commit)
Don't git commit --ammend
everytime, this will just keep amending your last commit. You want to keep your changes as change-sets that make sense.
不要git commit --ammend
每次都这样做,这只会不断修改您的最后一次提交。您希望将更改保留为有意义的更改集。