c********l 发帖数: 8138 | 1 对于"git reset --soft"命令,若不加任何branch或者文件名,单独运行该命令是干什
么用的??
具体上下文:
---------------------
git合并多次
适用于频繁本地commit提交者。
本地频繁commit后,在push时,所有的提交会push到服务器。
可以把本地的这些提交合并为一个提交,方法是:
git reset --soft 第一次本地commit的版本
git commit --amend
上面 “第一次本地commit的版本” 是你最后一次push后,本地的很多次提交中的第一
次的那个版本的hash,可以用git log查看。
--------------------
上面这段话我是这么理解的:
假设服务器最后一次push的版本是A1,然后本地依次commit(但没有push)的版本是
A2, A3, A4, A5, 此时,index和working copy都是A5
如果直接运行git push, 那么A2, a3, a4, a5都会出现在服务器上
所以原作者只希望服务器上出现A5,而不出现A2A3A4,到目前为止我是看明白了。
但是后面的我就没看明白,搞得云里雾里:
1,"git reset --soft"后,会发生哪些事?我的理解是这句命令根本不需要运行,
或者作者写错了
2. 作者说“git reset --soft,会(把HEAD指向)第一次本地commit的版本”
换句话,也就是A2版喽。但为什么是A2版本,而不是A1版(即最后一次远程push)
或者是A5版(即最后一次)? | N***r 发帖数: 2539 | 2
对于"git reset --soft"命令,若不加任何branch或者文件名,单独运行该命令是干什
么用的??
I guess 'git reset --soft' is invalid, you have to tell git how many commits
you want to rest 'softly', like, 'git reset --soft HEAD~1', which 'softly'
resets your last commit. When you do reset 'softly' and HEAD~1, the files
you modified and submitted in the last commit become 'modified but not
committed'. For example, in your last 'A5' commit, you modified one single
file 'src/foo.C', when you do 'git status' before you do reset, you will see
no modified files. When you do 'git log', you see something like
commit ****
A5
commit ****
A4
commit ****
A3
...
After you do 'get reset --soft HEAD~1', when you do 'git log', you see
commit ****
A4
commit ****
A3
...
A5 is gone, but whatever you changed in 'src/foo.C' is still in the file,
and when you do 'git status', you now see 'src/foo.C' is modified, like:
# Changes to be committed:
# (use "git reset HEAD ..." to unstage)
#
# modified: src/foo.C
Also, you can use 'git reset HEAD~1' to replace 'git reset --soft HEAD~1'.
But be careful the use of 'git reset --hard HEAD~1', it will remove whatever
you have done in the last commit.
具体上下文:
---------------------
git合并多次
适用于频繁本地commit提交者。
本地频繁commit后,在push时,所有的提交会push到服务器。
可以把本地的这些提交合并为一个提交,方法是:
git reset --soft 第一次本地commit的版本
git commit --amend
上面 “第一次本地commit的版本” 是你最后一次push后,本地的很多次提交中的第一
次的那个版本的hash,可以用git log查看。
--------------------
上面这段话我是这么理解的:
假设服务器最后一次push的版本是A1,然后本地依次commit(但没有push)的版本是
A2, A3, A4, A5, 此时,index和working copy都是A5
如果直接运行git push, 那么A2, a3, a4, a5都会出现在服务器上
所以原作者只希望服务器上出现A5,而不出现A2A3A4,到目前为止我是看明白了。
I don't think you can commit A5 without commit A2, A3 and A4. I guess 原作者
has A2,3,4,5 committed locally but s/he wants to push them as a single
commit to the 服务器 by combining A2,3,4,5 as a single commit, e.g., A2-3-4-
5.
Let me explain what s/he is doing…first A2,3,4,5 are local commit, if they
are just some temporary changes, i.e., A2 by itself did not finish a task,
while combined A2,3,4,5 does. S/he need to reset A5, 4, and 3, (not 2), by
doing 'git reset HEAD~3', then do 'git add whatever-need-to-be-added', then
'git commit --amend', now you have a single commit 'A2' with all changes
made in A2,3,4,5. This is stupid …. I would to this, 'git reset HEAD~4',
then "git commit -a -m 'this is the combined A2,3,4,5' "
A fancier way to do this, use 'squash', do this, 'git rebase -i HEAD~4',
you will see something like:
pick **** A2
pick **** A3
pick **** A4
pick **** A5
you change them to
pick **** A2
s **** A3
s **** A4
s **** A5
save the file and quit, another text editor will show and let you to edit
the commit messages. anyway, give it a try.
但是后面的我就没看明白,搞得云里雾里:
1,"git reset --soft"后,会发生哪些事?我的理解是这句命令根本不需要运行,
或者作者写错了
[yes, should be git reset HEAD~n]
2. 作者说“git reset --soft,会(把HEAD指向)第一次本地commit的版本”
换句话,也就是A2版喽。但为什么是A2版本,而不是A1版(即最后一次远程push)
或者是A5版(即最后一次)?
depends how many HEAD you reset
【在 c********l 的大作中提到】 : 对于"git reset --soft"命令,若不加任何branch或者文件名,单独运行该命令是干什 : 么用的?? : 具体上下文: : --------------------- : git合并多次 : 适用于频繁本地commit提交者。 : 本地频繁commit后,在push时,所有的提交会push到服务器。 : 可以把本地的这些提交合并为一个提交,方法是: : git reset --soft 第一次本地commit的版本 : git commit --amend
| c********l 发帖数: 8138 | 3 Thanks
最怕这种原文有错误的.....
commits
'
see
【在 N***r 的大作中提到】 : : 对于"git reset --soft"命令,若不加任何branch或者文件名,单独运行该命令是干什 : 么用的?? : I guess 'git reset --soft' is invalid, you have to tell git how many commits : you want to rest 'softly', like, 'git reset --soft HEAD~1', which 'softly' : resets your last commit. When you do reset 'softly' and HEAD~1, the files : you modified and submitted in the last commit become 'modified but not : committed'. For example, in your last 'A5' commit, you modified one single : file 'src/foo.C', when you do 'git status' before you do reset, you will see : no modified files. When you do 'git log', you see something like
| l*******m 发帖数: 1096 | 4 never used it before
please look at a very good one:
http://stackoverflow.com/questions/2530060/can-you-explain-what
【在 c********l 的大作中提到】 : 对于"git reset --soft"命令,若不加任何branch或者文件名,单独运行该命令是干什 : 么用的?? : 具体上下文: : --------------------- : git合并多次 : 适用于频繁本地commit提交者。 : 本地频繁commit后,在push时,所有的提交会push到服务器。 : 可以把本地的这些提交合并为一个提交,方法是: : git reset --soft 第一次本地commit的版本 : git commit --amend
| t**********h 发帖数: 2273 | |
|