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

2016-01-10 17:29:04 +08:00
 eightqueen
场景是这样的,我修改了 20 个 java 文件, 1 个 xml 文件,我希望提交 20 个 java 文件的修改, xml 文件还需要进一步完善。可是 20 个 java 文件一个一个去 add ,感觉好 low ,又不能直接执行“ git add .”。
10385 次点击
所在节点    程序员
11 条回复
sophymax
2016-01-10 17:30:32 +08:00
git stash
guchengf
2016-01-10 17:36:40 +08:00
你可以 add .
然后 reset xml

或者

https://github.com/ndbroadbent/scm_breeze
Vvfan
2016-01-10 17:45:12 +08:00
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
2016-01-10 17:45:43 +08:00
暂存 然后提交了再取出?
cloudzhou
2016-01-10 17:46:32 +08:00
git status|grep modified|grep java$|awk '{print $NF}'|xargs git add
linhua
2016-01-10 17:48:06 +08:00
finian
2016-01-10 17:57:41 +08:00
用 GUI 吧,比如 SourceTree ,直观省事
crayygy
2016-01-10 18:05:15 +08:00
git add *.java ?
az
2016-01-10 18:07:09 +08:00
可以临时 checkout 到一个新的分支 commit ,完了再回来,在 reset 。
chemzqm
2016-01-10 18:08:22 +08:00
git add **/*.java
或者
git add .
git reset --- path-to-xml
不加 hard git 不会动工作目录
timwu
2016-01-10 18:56:16 +08:00
git stash 正解,推荐 sourcetree

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/249703

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX