由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - "git reset --soft"具体是干什么用处的?
相关主题
问个面试题为啥 c++ bitset 的大小一定要在编译时给呢?
来,周末福利,cap理论里面的三种策略python的问题,大拿帮忙看看
SVN howto: branch working copy changes without committing? (转载)菜鸟问个C++问题
卫东大牛组织下挑战Zillow challenge?class的Init()和Reset()需要考虑thread-safe吗?
svn/cvs怎么样设置使得只保存最新版本? (转载)好久没用C++了,想用静态变量写一个简单双向链表,一直报错
删去单向LINKED LIST中的一个节点,假设HEAD is unknownreset button and checkbox question in the webpage (转载)
刚到head first的design pattern怎样除去循环链
lex/yacc如何reset buffer?OCEF招JOOMLA/PHP 和网站设计义工 (转载)
相关话题的讨论汇总
话题: git话题: commit话题: a2话题: reset话题: a5
进入Programming版参与讨论
1 (共1页)
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
5
只会git reset --hard,
杯具
1 (共1页)
进入Programming版参与讨论
相关主题
OCEF招JOOMLA/PHP 和网站设计义工 (转载)svn/cvs怎么样设置使得只保存最新版本? (转载)
git问题删去单向LINKED LIST中的一个节点,假设HEAD is unknown
Google+ Head Vic Gundotra Leaving Company (转载)刚到head first的design pattern
初学JavaScript,问一个小问题lex/yacc如何reset buffer?
问个面试题为啥 c++ bitset 的大小一定要在编译时给呢?
来,周末福利,cap理论里面的三种策略python的问题,大拿帮忙看看
SVN howto: branch working copy changes without committing? (转载)菜鸟问个C++问题
卫东大牛组织下挑战Zillow challenge?class的Init()和Reset()需要考虑thread-safe吗?
相关话题的讨论汇总
话题: git话题: commit话题: a2话题: reset话题: a5