我试图弄清楚如何在许多未提交的更改中存储两个特定的文件。
这个非常有前途的答案是,在Git更改的多个文件中,仅存储一个文件?,但未显示用法,因此无法解决。
以下内容不起作用,并且手册页不是很有帮助(它似乎是在谈论终端输出,而不是实际存储)。我想藏匿application.conf
和plugins.sbt
,然后提交一切。
app (master)$ git status
On branch master
Your branch is ahead of 'origin/master' by 29 commits.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: views/mobile/blog.scala.html
modified: views/mobile/slideshow.scala.html
modified: ../public/css/mobile/styles.css
Unmerged paths:
(use "git reset HEAD <file>..." to unstage)
(use "git add <file>..." to mark resolution)
both modified: ../conf/application.conf
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: ../project/plugins.sbt
app (master)$ git stash -p ../conf/application.conf ../project/plugins.sbt
usage: git stash list [<options>]
or: git stash show [<stash>]
or: git stash drop [-q|--quiet] [<stash>]
or: git stash ( pop | apply ) [--index] [-q|--quiet] [<stash>]
or: git stash branch <branchname> [<stash>]
or: git stash [save [--patch] [-k|--[no-]keep-index] [-q|--quiet]
[-u|--include-untracked] [-a|--all] [<message>]]
or: git stash clear
利用
git stash --patch
对于可能提交中的每个大块,git都会显示如下对话框:
diff --git files over files
index e69de29..ac4f3b3 100644
--- a/file.txt
+++ b/file.txt
@@ -0,0 +1 @@
+you did awesome stuff!
Stash this hunk [y,n,q,a,d,/,e,?]?
大块是git-diff产生的线条的连贯差异。要选择一个文件d
,只要您到达该文件,就必须取消添加块,然后您可以a
从该文件中添加所有块。
您还可以通过用y
es回答问题来选择一个大块头。如果块看起来太大,您甚至可以s
将其拆分。也可以e
驱散当前的大块头。
使用--patch
-option上不同GIT中的命令是可能的(FE stash
,commit
和add
)。
这是--patch
-function的详细说明,我从开发人员文档中获取了该信息:
This lets you choose one path out of a 'status' like selection.
After choosing the path, it presents the diff between the index
and the working tree file and asks you if you want to stage
the change of each hunk. You can select one of the following
options and type return:
y - stage this hunk
n - do not stage this hunk
q - quit; do not stage this hunk or any of the remaining ones
a - stage this hunk and all later hunks in the file
d - do not stage this hunk or any of the later hunks in the file
g - select a hunk to go to
/ - search for a hunk matching the given regex
j - leave this hunk undecided, see next undecided hunk
J - leave this hunk undecided, see next hunk
k - leave this hunk undecided, see previous undecided hunk
K - leave this hunk undecided, see previous hunk
s - split the current hunk into smaller hunks
e - manually edit the current hunk
? - print help
如果您对一种更舒适的方式来完成此任务感兴趣,则可以使用git gui工具(例如LazyGit)。我用这个将我的日常工作分解成原子提交。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句