• 请不要在回答技术问题时复制粘贴 AI 生成的内容
eightqueen
V2EX  ›  程序员

git 如何指定某个文件暂时不提交?

  •  
  •   eightqueen · Jan 10, 2016 · 10907 views
    This topic created in 3800 days ago, the information mentioned may be changed or developed.
    场景是这样的,我修改了 20 个 java 文件, 1 个 xml 文件,我希望提交 20 个 java 文件的修改, xml 文件还需要进一步完善。可是 20 个 java 文件一个一个去 add ,感觉好 low ,又不能直接执行“ git add .”。
    11 replies    2016-01-10 18:56:16 +08:00
    sophymax
        1
    sophymax  
       Jan 10, 2016 via Android
    git stash
    guchengf
        2
    guchengf  
       Jan 10, 2016
    你可以 add .
    然后 reset xml

    或者

    https://github.com/ndbroadbent/scm_breeze
    Vvfan
        3
    Vvfan  
       Jan 10, 2016
    git update-index

    --[no-]assume-unchanged
    When this flag is specified, the object names recorded for the paths
    are not updated. Instead, this option sets/unsets the "assume
    unchanged" bit for the paths. When the "assume unchanged" bit is on,
    the user promises not to change the file and allows Git to assume that
    the working tree file matches what is recorded in the index. If you
    want to change the working tree file, you need to unset the bit to
    tell Git. This is sometimes helpful when working with a big project on
    a filesystem that has very slow lstat(2) system call (e.g. cifs).

    Git will fail (gracefully) in case it needs to modify this file in the
    index e.g. when merging in a commit; thus, in case the
    assumed-untracked file is changed upstream, you will need to handle
    the situation manually.
    zapper
        4
    zapper  
       Jan 10, 2016 via iPhone
    暂存 然后提交了再取出?
    cloudzhou
        5
    cloudzhou  
       Jan 10, 2016
    git status|grep modified|grep java$|awk '{print $NF}'|xargs git add
    linhua
        6
    linhua  
       Jan 10, 2016
    finian
        7
    finian  
       Jan 10, 2016
    用 GUI 吧,比如 SourceTree ,直观省事
    crayygy
        8
    crayygy  
       Jan 10, 2016
    git add *.java ?
    az
        9
    az  
       Jan 10, 2016
    可以临时 checkout 到一个新的分支 commit ,完了再回来,在 reset 。
    chemzqm
        10
    chemzqm  
       Jan 10, 2016
    git add **/*.java
    或者
    git add .
    git reset --- path-to-xml
    不加 hard git 不会动工作目录
    timwu
        11
    timwu  
       Jan 10, 2016
    git stash 正解,推荐 sourcetree
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   898 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 58ms · UTC 22:10 · PVG 06:10 · LAX 15:10 · JFK 18:10
    ♥ Do have faith in what you're doing.