什么被认为是保持未分阶段变化的更好方法:" git stash"或者" git diff到补丁文件"?

时间:2014-11-16 15:29:41

标签: git

[gdaniel@vnc23 sx_fit_regression]$ git status
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   eth/utilities/eth_constants.py
#       modified:   eth/utilities/eth_fdb_tools.py
#       modified:   libs/tools/string_manipulation_tools.py
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       .project
#       .pydevproject
#       eth/fdb/configuration/
no changes added to commit (use "git add" and/or "git commit -a")
[gdaniel@vnc23 sx_fit_regression]$

[gdaniel@vnc23 sx_fit_regression]$ git fetch origin master
From file:///mswg/git/switchx/sx_fit_regression
 * branch            master     -> FETCH_HEAD

[gdaniel@vnc23 sx_fit_regression]$ git rebase --merge FETCH_HEAD
cannot rebase: you have unstaged changes
M       eth/utilities/eth_constants.py
M       eth/utilities/eth_fdb_tools.py
M       libs/tools/string_manipulation_tools.py
[gdaniel@vnc23 sx_fit_regression]$

正如你所看到的,我无法改变,因为我有未经修改的变化。

假设我需要将上面的代码更改推送到GIT中。

据我所知,这是流程:

"Code Review -> commit -> fetch -> rebase -> push"

假设我不能在给定的一周内对上述3个文件进行代码审查......我想继续处理需要修改代码的其他2个文件,并且今天可以对这2个文件进行代码审查。

为此,我需要保留3个文件的更改。

  1. 什么是更好的:&#34; git stash&#34;或&#34; git diff到补丁文件&#34;
  2.   

    git diff HEAD~..HEAD文件名&gt; fileA.patch

    1. 如何分别存储3个文件?
    2. 谢谢,

      的Qwerty

2 个答案:

答案 0 :(得分:2)

只需将3个文件提交到新分支即可。分店很便宜。

git checkout -b branch-3-files
git commit -a
git checkout master
git pull
... work on other 2 files ...
git commit
git push
... review original 3 files ...
git merge branch-3-files
git push

答案 1 :(得分:0)

默认情况下,创建存储将始终保存整个状态。但是,您可以使用修补程序功能以交互方式选择要隐藏的更改。要做到这一点,只需简单地使用--patch-p进行调用。

至于与补丁的比较,您需要考虑存储是内置的解决方案,以“收起”当前状态并清理工作目录,以便您暂时可以处理其他事情。如果您习惯使用补丁,那么使用补丁似乎更直观,但通常您不需要手动处理该程序,而只能使用Git的机制。

使用stashes有好处,因为stas就像提交一样,Git还存储了作者,日期和消息等元数据。最重要的是,它还包含指向父提交的指针,因此当您稍后应用存储时,它可以计算差异,并且自动合并存储与其间可能发生的任何更改。使用补丁时,您必须手动解决任何问题。