Githug 过关攻略

Notice: The article is not finished.

  1. 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    ********************************************************************************
    * Githug *
    ********************************************************************************

    Name: cherry-pick
    Level: 42
    Difficulty: ***

    Your new feature isn't worth the time and you're going to delete it. But it has one commit that fills in `README` file, and you want this commit to be on the ma ster as well.

    $ git branch
    master
    new-feature
    $ git checkout new-feature
    Switched to branch 'new-feature'
    $ git log -p
    commit ea2a47c19b85fc321e2737ddc49db3deeba3a1b5
    Author: Andrey <aslushnikov@gmail.com>
    Date: Wed Mar 28 02:28:35 2012 +0400

    some small fixes

    diff --git a/new-feature.js b/new-feature.js
    index a214bad..14ad8f1 100644
    --- a/new-feature.js
    +++ b/new-feature.js
    @@ -1,3 +1,4 @@
    function newFeature () {
    console.log("Now the feature works!");
    + console.log("And the output even more nice!");
    }

    commit 4a1961bce62840eaef9c4392fe5cc799e38c9b7b
    Author: Andrey <aslushnikov@gmail.com>
    Date: Wed Mar 28 02:27:18 2012 +0400

    Fixed feature

    diff --git a/new-feature.js b/new-feature.js
    index d502e68..a214bad 100644
    --- a/new-feature.js
    +++ b/new-feature.js
    @@ -1,3 +1,3 @@
    function newFeature () {
    - throw new Error("Not implemented yet! :(");
    + console.log("Now the feature works!");
    }

    commit ca32a6dac7b6f97975edbe19a4296c2ee7682f68
    Author: Andrey <aslushnikov@gmail.com>
    :
    function newFeature () {
    console.log("Now the feature works!");
    + console.log("And the output even more nice!");
    }

    commit 4a1961bce62840eaef9c4392fe5cc799e38c9b7b
    Author: Andrey <aslushnikov@gmail.com>
    Date: Wed Mar 28 02:27:18 2012 +0400

    Fixed feature

    diff --git a/new-feature.js b/new-feature.js
    index d502e68..a214bad 100644
    --- a/new-feature.js
    +++ b/new-feature.js
    @@ -1,3 +1,3 @@
    function newFeature () {
    - throw new Error("Not implemented yet! :(");
    + console.log("Now the feature works!");
    }

    commit ca32a6dac7b6f97975edbe19a4296c2ee7682f68
    Author: Andrey <aslushnikov@gmail.com>
    Date: Wed Mar 28 02:25:51 2012 +0400

    Filled in README.md with proper input

    diff --git a/README.md b/README.md
    index 54f3308..c60c612 100644
    --- a/README.md
    +++ b/README.md
    @@ -1,2 +1 @@
    -I'll fill in the file some time later..
    -
    +This project is a FAKE.

    commit 58a8c8edcfdd00c6d8cce9aada8f987a1677571f
    Author: Andrey <aslushnikov@gmail.com>
    Date: Wed Mar 28 02:24:41 2012 +0400

    Added a stub for the feature

    diff --git a/new-feature.js b/new-feature.js
    new file mode 100644
    index 0000000..d502e68
    --- /dev/null
    +++ b/new-feature.js
    @@ -0,0 +1,3 @@
    +function newFeature () {
    + throw new Error("Not implemented yet! :(");
    +}

    commit ea3dbcc5e2d2359698c3606b0ec44af9f76def54
    Author: Andrey <aslushnikov@gmail.com>
    Date: Wed Mar 28 02:20:32 2012 +0400

    Initial commit

    diff --git a/README.md b/README.md
    new file mode 100644
    index 0000000..54f3308
    --- /dev/null
    +++ b/README.md
    @@ -0,0 +1,2 @@
    +I'll fill in the file some time later..
    +

    $ git checkout master
    Switched to branch 'master'

    $ git cherry-pick ca32a6dac7b6f97975edbe19a4296c2ee7682f68
    [master e679245] Filled in README.md with proper input
    Author: Andrey <aslushnikov@gmail.com>
    Date: Wed Mar 28 02:25:51 2012 +0400
    1 file changed, 1 insertion(+), 2 deletions(-)

    $

    $ githug
    ********************************************************************************
    * Githug *
    ********************************************************************************
    Congratulations, you have solved the level!
  1. 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    Name: grep
    Level: 43
    Difficulty: **

    Your project's deadline approaches, you should evaluate how many TODOs are left in your code

    $ git grep TODO
    app.rb:# TODO Make site url variable.
    app.rb:# TODO Make API version variable.
    app.rb:# TODO Redirecting queries could be useful.
    config.rb: # TODO Move password to a configuration file.

    ********************************************************************************
    * Githug *
    ********************************************************************************
    How many items are there in your todolist? 4
    Congratulations, you have solved the level!
  2. 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    Name: rename_commit
    Level: 44
    Difficulty: ***

    Correct the typo in the message of your first (non-root) commit.

    $ githug hint
    ********************************************************************************
    * Githug *
    ********************************************************************************
    Take a look the `-i` flag of the rebase command.

    $ git log
    commit 5bda4a0b0a1d00fc10e24fa8eb39893bbd44dbb6
    Author: aprikyblue <aprikyblue@gmail.com>
    Date: Sat Jan 2 09:20:32 2016 +0800

    Second commit

    commit a95c21b1de5bad5f5c2840dd99961d9932788ad3
    Author: aprikyblue <aprikyblue@gmail.com>
    Date: Sat Jan 2 09:20:32 2016 +0800

    First coommit

    commit 51189867a8b3bd4a33c5e2414474ba41c7dac273
    Author: aprikyblue <aprikyblue@gmail.com>
    Date: Sat Jan 2 09:20:32 2016 +0800

    Initial commit

    $ git rebase -i HEAD~2

    edit a95c21b First coommit
    pick 5bda4a0 Second commit

    # Rebase 5118986..5bda4a0 onto 5118986 (2 command(s))
    #
    # Commands:
    # p, pick = use commit
    # r, reword = use commit, but edit the commit message
    # e, edit = use commit, but stop for amending
    # s, squash = use commit, but meld into previous commit
    # f, fixup = like "squash", but discard this commit's log message
    # x, exec = run command (the rest of the line) using shell
    # d, drop = remove commit
    #
    # These lines can be re-ordered; they are executed from top to bottom.
    #
    # If you remove a line here THAT COMMIT WILL BE LOST.
    #
    # However, if you remove everything, the rebase will be aborted.
    #
    # Note that empty commits are commented out

    Stopped at a95c21b1de5bad5f5c2840dd99961d9932788ad3... First coommit
    You can amend the commit now, with

    git commit --amend

    Once you are satisfied with your changes, run

    git rebase --continue

    $ git commit --amend
    First commit

    # Please enter the commit message for your changes. Lines starting
    # with '#' will be ignored, and an empty message aborts the commit.
    #
    # Date: Sat Jan 2 09:20:32 2016 +0800
    #
    # interactive rebase in progress; onto 5118986
    # Last command done (1 command done):
    # edit a95c21b First coommit
    # Next command to do (1 remaining command):
    # pick 5bda4a0 Second commit
    # You are currently editing a commit while rebasing branch 'master' on '5118986'.
    #
    # Changes to be committed:
    # new file: file1
    #

    [detached HEAD 01d8236] First coomit
    Date: Sat Jan 2 09:20:32 2016 +0800
    1 file changed, 0 insertions(+), 0 deletions(-)
    create mode 100644 file1

    $ git rebase --continue
    Successfully rebased and updated refs/heads/master.

    $ git log
    commit c5833d2d6e290cb4a0818c577fafd0fdf1108832
    Author: aprikyblue <aprikyblue@gmail.com>
    Date: Sat Jan 2 09:20:32 2016 +0800

    Second commit

    commit fa3311c1aecc9e6db2b5560bf0f55725e2dedf4c
    Author: aprikyblue <aprikyblue@gmail.com>
    Date: Sat Jan 2 09:20:32 2016 +0800

    First commit

    commit 51189867a8b3bd4a33c5e2414474ba41c7dac273
    Author: aprikyblue <aprikyblue@gmail.com>
    Date: Sat Jan 2 09:20:32 2016 +0800

    Initial commit

    $ githug
    ********************************************************************************
    * Githug *
    ********************************************************************************
    Congratulations, you have solved the level!

  3. 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    Name: squash
    Level: 45
    Difficulty: ****

    You have committed several times but would like all those changes to be one commit.

    $ git log
    commit 541411049943349e912a07f37c6d064bad5ec92a
    Author: aprikyblue <aprikyblue@gmail.com>
    Date: Sat Jan 2 09:27:01 2016 +0800

    Updating README

    commit ef96ffbe32a01343d28ba69f8c87b94ee185c97d
    Author: aprikyblue <aprikyblue@gmail.com>
    Date: Sat Jan 2 09:27:01 2016 +0800

    Updating README

    commit 3c0b0706f7a45b5c3beff1cb24adb334b1ad919d
    Author: aprikyblue <aprikyblue@gmail.com>
    Date: Sat Jan 2 09:27:01 2016 +0800

    Updating README

    commit 41efe40f711dbdba06e511c60c3eacf5f582a952
    Author: aprikyblue <aprikyblue@gmail.com>
    Date: Sat Jan 2 09:27:01 2016 +0800

    Adding README

    commit 7ccc77cd3818b042ebea72703016ce87e4fb7bd2
    Author: aprikyblue <aprikyblue@gmail.com>
    Date: Sat Jan 2 09:27:01 2016 +0800

    Initial Commit

    $ git rebase -i 41efe40f711dbdba06e511c60c3eacf5f582a952

    pick 41efe4 Adding README
    squash 3c0b070 Updating README
    squash ef96ffb Updating README
    squash 5414110 Updating README

    Rebasing (4/4)

    # This is a combination of 4 commits.
    # The first commit's message is:
    Updating README

    [detached HEAD 6e091a2] Updating README
    Date: Sat Jan 2 09:27:01 2016 +0800
    1 file changed, 3 insertions(+)
    create mode 100644 README
    Successfully rebased and updated refs/heads/master.

    $ githug
    ********************************************************************************
    * Githug *
    ********************************************************************************
    Congratulations, you have solved the level!
  4. 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    Name: merge_squash
    Level: 46
    Difficulty: ***

    Merge all commits from the long-feature-branch as a single commit.
    $ githug hint
    ********************************************************************************
    * Githug *
    ********************************************************************************
    Take a look at the `--squash` option of the merge command. Don't forget to commit the merge!

    $ git branch
    long-feature-branch
    * master

    $ git merge long-feature-branch --squash
    Squash commit -- not updating HEAD
    Automatic merge went well; stopped before committing as requested

    $ git commit
    [master f90f224] Squashed commit of the following:
    1 file changed, 3 insertions(+)
    create mode 100644 file3

    $ githug
    ********************************************************************************
    * Githug *
    ********************************************************************************
    Congratulations, you have solved the level!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Name: reorder
Level: 47
Difficulty: ****

You have committed several times but in the wrong order. Please reorder your commits.

$ git log
commit d198f3d2e4bb1629aba89216909ede75a58df64a
Author: aprikyblue <aprikyblue@gmail.com>
Date: Sun Jan 31 22:11:19 2016 +0800

Second commit

commit 5fe48ad01f3c45dc54195c6ff64548a36065a5f4
Author: aprikyblue <aprikyblue@gmail.com>
Date: Sun Jan 31 22:11:18 2016 +0800

Third commit

commit eab7c443b769dd81cb95acc494376a263069d0cc
Author: aprikyblue <aprikyblue@gmail.com>
Date: Sun Jan 31 22:11:18 2016 +0800

First commit

commit 45a91e306f3c32bd5357d682e742a70ec83e8f43
Author: aprikyblue <aprikyblue@gmail.com>
Date: Sun Jan 31 22:11:18 2016 +0800

Initial Setup


$ git rebase -i HEAD~3

pick eab7c44 First commit
pick d198f3d Second commit
pick 5fe48ad Third commi

Rebasing (3/3)

Successfully rebased and updated refs/heads/master.

$ githug
********************************************************************************
* Githug *
********************************************************************************
Congratulations, you have solved the level!
1
2
3
4
5
6
Name: bisect
Level: 48
Difficulty: ***

A bug was introduced somewhere along the way. You know that running `ruby prog.rb 5` should output 15. You can also run `make test`. What are the first 7 chars of the hash of the commit that introduced the bug.

Donate
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.

请我喝杯咖啡吧~

支付宝
微信