【问题标题】:Committing partial Hunks in Git在 Git 中提交部分数据
【发布时间】:2011-07-07 03:41:55
【问题描述】:

如果我做了两个逻辑更改,这在代码中是连续的。 Git 在交互式添加时将其显示为一个大块。

有没有办法在add --patch 期间专门只添加几行代码?

【问题讨论】:

标签: git msysgit


【解决方案1】:

git add --patch mode 具有拆分单个大块或编辑单个大块的选项。

git add --patch:

s - split the current hunk into smaller hunks
e - manually edit the current hunk

这不能解决您关于连续线集的问题吗?

添加部分提交后,用户应仅使用git commit 提交,使用git commit -a 或使用带有all files 标志的提交忽略添加的部分并提交所有暂存文件。

【讨论】:

  • 注意:对我来说,在仅向索引添加一些大块之后通过git commit(没有git commit -a)提交是不够的。尽管git diffgit diff --cached 以及git status 给出了预期的输出,但发出git commit 将所有更改全部添加到提交中。我之前必须使用git stash --keep-index,临时存储其他更改,部分提交,然后git stash pop 将它们添加回工作副本。 Msysgit 1.7.11 @ WinXP。 YMMV。
猜你喜欢
  • 2011-06-15
  • 2016-04-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-12
  • 2010-11-13
  • 1970-01-01
  • 2016-12-25
相关资源
最近更新 更多