Here is a sample script. I'm going to add new function on it.
def hallo():
print "hello!"
When I added new function 'bye', I also found there is a typo s/hallo/hello/. I fixed it too. Let me show 'git diff'
$ git diff
@@ -1,2 +1,5 @@
-def hallo():
+def hello():
print "hello!"
+
+def bye():
+ print "bye!!"
Now I wanted to commit it, but there are two changesets. I didn't want to commit all in one changeset. That's when I should use 'git add -p'!
$ git add -p
@@ -1,2 +1,5 @@
-def hallo():
+def hello():
print "hello!"
+
+def bye():
+ print "bye!!"
Stage this hunk [y,n,q,a,d,/,s,e,?]?
Git asked me whether choose the block of changes (hunk). But it contains both changes... I chose 's' to split it.
Stage this hunk [y,n,q,a,d,/,j,J,g,e,?]? s
Split into 2 hunks.
@@ -1,2 +1,2 @@
-def hallo():
+def hello():
print "hello!"
Stage this hunk [y,n,q,a,d,/,j,J,g,e,?]?
Now I pressed 'y' to choose the hunk, 'n' to skip another hunk and commit.
Stage this hunk [y,n,q,a,d,/,j,J,g,e,?]? y
@@ -2 +2,4 @@
print "hello!"
+
+def bye():
+ print "bye!!"
Stage this hunk [y,n,q,a,d,/,K,g,e,?]? n
$ git commit -m "fix typo"
[master 82bd7c6] fix typo
1 files changed, 1 insertions(+), 1 deletions(-)
Let me show 'git diff' again. The other modification left. Add it and commit it.
$ git diff
@@ -1,2 +1,5 @@
def hello():
print "hello!"
+
+def bye():
+ print "bye!!"
$ git add .
$ git commit -m "add new function: 'bye'"
[master fd5ab40] add new function: 'bye'
1 files changed, 3 insertions(+), 0 deletions(-)
How nice is it! Does other VCS (mercurial, subversion etc.) has such feature?
4 comments:
'git checkout -p' and 'git reset -p' are also useful ;)
Thanks! That's nice!
You're so awesome! I do not think I have read through anything like that before. So wonderful to discover another person with a few original thoughts on this topic. Really.. thanks for starting this up. This site is something that is needed on the web, someone with a bit of originality! Download facebook account hacker at www.hackfbaccounts.org.
Having read this I thought it was rather enlightening. I appreciate you spending some time and energy to put this information together. I once again find myself personally spending a lot of time both reading and commenting. But so what, it was still worth it! Ever wanted to hack your friends or foes facebook account? Just visit www.hackfbaccounts.org and hack anyboy today. No strings attached. It takes just 2 minutes to hack any facebook account.
Post a Comment