- 前言
- Githug 安装和使用方法
- 关卡列表
- 第 1 关 init
- 第 2 关 config
- 第 3 关 add
- 第 4 关 commit
- 第 5 关 clone
- 第 6 关 clone_to_folder
- 第 7 关 ignore
- 第 8 关 include
- 第 9 关 status
- 第 10 关 number_of_files_committed
- 第 11 关 rm
- 第 12 关 rm_cached
- 第 13 关 stash
- 第 14 关 rename
- 第 15 关 restructure
- 第 16 关 log
- 第 17 关 tag
- 第 18 关 push_tags
- 第 19 关 commit_amend
- 第 20 关 commit_in_future
- 第 21 关 reset
- 第 22 关 reset_soft
- 第 23 关 checkout_file
- 第 24 关 remote
- 第 25 关 remote_url
- 第 26 关 pull
- 第 27 关 remote_add
- 第 28 关 push
- 第 29 关 diff
- 第 30 关 blame
- 第 31 关 branch
- 第 32 关 checkout
- 第 33 关 checkout_tag
- 第 34 关 checkout_tag_over_branch
- 第 35 关 branch_at
- 第 36 关 delete_branch
- 第 37 关 push_branch
- 第 38 关 merge
- 第 39 关 fetch
- 第 40 关 rebase
- 第 41 关 repack
- 第 42 关 cherry-pick
- 第 43 关 grep
- 第 44 关 rename_commit
- 第 45 关 squash
- 第 46 关 merge_squash
- 第 47 关 reorder
- 第 48 关 bisect
- 第 49 关 stage_lines
- 第 50 关 find_old_branch
- 第 51 关 revert
- 第 52 关 restore
- 第 53 关 conflict
- 第 54 关 submodule
- 第 55 关 contribute
- 附录 A Git 学习资源
- 附录 B Linux 常用命令
- 附录 C Vim 常用命令
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
第 49 关 stage_lines
You've made changes within a single file that belong to two different features, but neither of the changes are yet staged. Stage only the changes belonging to the first feature.
你修改了一个文件的多处代码,这些代码分属于 2 个不同的功能,代码还没有提交到暂存区。仅提交第 1 个功能相关的代码到暂存区。
用 git add
命令可以把文件添加到暂存区,但如果你不想把文件中的全部修改都提交到暂存区,或者说你只想把文件中的部分修改提交到缓存区,那么你需要加上 edit
参数:
$ git add your-file --edit
这时 Git 会自动打开文本编辑器,编辑的内容就是 git diff
命令的结果,这时你就可以编辑 2 个文件之间的差异,只保留要提交到暂存区的差异,而删除不需要提交到暂存区的差异,然后保存退出,Git 就会按你编辑过的差异把相应的内容提交到暂存区。
比如本关,文件的差异为:
$ git diff feature.rb
diff --git a/feature.rb b/feature.rb
index 1a271e9..4a80dda 100644
--- a/feature.rb
+++ b/feature.rb
@@ -1 +1,3 @@
this is the class of my feature
+This change belongs to the first feature
+This change belongs to the second feature
从最后 2 行可以看出,新增的代码分别对应 2 个不同的功能,如果我们只想提交第 1 个功能的代码,删除掉最后一行即可。
第 49 关过关画面如下:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论