Git:如何使用stash -p存放特定文件? [英] Git: how to use stash -p to stash specific files?

查看:2168
本文介绍了Git:如何使用stash -p存放特定文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚如何在许多未提交的更改中存储两个特定的文件.

I'm trying to figure out how to stash two specific files among many uncommitted changes.

这个非常有前途的答案,

This very promising answer, Stash only one file out of multiple files that have changed with Git?, doesn't show the usage and I'm having trouble working it out.

以下内容不起作用,并且手册页不是很有帮助(它似乎是在谈论终端输出,而不是实际存储).我想隐藏application.confplugins.sbt,然后提交其他所有内容.

The following doesn't work and the man page isn't very helpful (it appears to talk about terminal output, not actually stashing). I want to stash application.conf and plugins.sbt and then commit everything else.

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将针对您可能提交的每个大块显示如下对话框:

git will then show a dialog like the following, for every hunk in your possible commit:

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 ecline重复添加块,然后您可以从该文件中添加a ll块.

A hunk is a coherent diff of lines as git-diff produces it. To select a single file you'll have to decline adding hunks as long as you reach that file, then you might add all hunks from that file.

您还可以通过使用y es回答问题来选择一个大块头.如果块看起来太大,您甚至可以s将其拆分.也可以e滴下当前的大块头.

You're also able to choose a single hunk by answering the question with yes. If the hunk seems to be too big, you even might split it. It is also possible to edit the current hunk.

在不同的git命令(例如stashcommitadd)上可以使用--patch选项.

Using the --patch-option is possible on different git commands (f.e. stash, commit and add).

这是--patch功能的详细说明,我从开发人员文档:

This is the detailed explanation of the --patch-function, which i grabbed from the developers documentation:

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:如何使用stash -p存放特定文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆