如何通过 git 状态下的编号将特定文件添加到 git 中?
How to add specific files in git by their number in git status?
我经常遇到以下场景:
modified: assembly/main.debug.s
modified: ../src/cd/Config.java
modified: ../src/cd/memoization/cfg/SubgraphFinder.java
modified: ../src/cd/memoization/cfg/SubgraphMap.java
modified: ../src/cd/profiler/Profile.java
modified: ../test/cd/test/TestSamplePrograms.java
modified: ../../notes/20150521.txt
这里我有一堆文件,我想将它们包含在不同的提交中。到目前为止,我所做的是做一堆 git add <pathspec>
,然后是相应的 git commit
。 <pathspec>
是让我恼火的地方。有没有类似下面的东西?
1 modified: assembly/main.debug.s
2 modified: ../src/cd/Config.java
3 modified: ../src/cd/memoization/cfg/SubgraphFinder.java
4 modified: ../src/cd/memoization/cfg/SubgraphMap.java
5 modified: ../src/cd/profiler/Profile.java
6 modified: ../test/cd/test/TestSamplePrograms.java
7 modified: ../../notes/20150521.txt
git magic 2,3,5 -m "My super simple commit"
示例回购:
我正在使用包含四个文件的示例存储库:a、b、c、d。
这里a
被跟踪、更改和上演; b
被跟踪、更改且未上演; c
在未跟踪和分阶段; d
只是未被追踪。
外部工具:git-number
When run without arguments, 'git number' runs 'git status' and attach a unique number for each line of filename printed by 'git status', and it will 'remember' this number-to-filename association. When run with arguments, like this:
$ git number <any git command> [one or more numbers or git options/args]
'git number' will run that and subtitute all the numbers to their equivalent filenames. Non-numeric argument are passed intact to git.
这适用于其他命令。
外部工具:SCM Breeze
SCM Breeze is a set of shell scripts (for bash and zsh) that enhance your interaction with git. It integrates with your shell to give you numbered file shortcuts, a repository index with tab completion, and many other useful features.
SCM Breeze 利用键盘快捷键和别名按编号处理 git 个文件:
Ctrl + x, c => git_add_and_commit
- 添加给定文件(如果有),然后提交暂存更改
Ctrl + x, Space => git_commit_all
- 提交所有内容
git add
:
$ ga 1
git diff
:
$ gd 2
git reset
:
$ grs 3
git commit
:
$ gco 4
使用 git add -i
的原生方式
git add -i
来自 Git reference:
-i
--interactive
Add modified contents in the working tree interactively to the index. Optional path arguments may be supplied to limit operation to a subset of the working tree. See “Interactive mode” for details.
您可以将此记为 -i
直观,因为界面非常直观。好吧,至少对硬核 Vim 用户来说是这样。
打开交互模式:
添加(暂存)跟踪文件:
添加一个未跟踪的文件:
查看变化:
如果您在添加过程中遇到困难,请使用空字符串点击 Return。
注:
我经常遇到以下场景:
modified: assembly/main.debug.s
modified: ../src/cd/Config.java
modified: ../src/cd/memoization/cfg/SubgraphFinder.java
modified: ../src/cd/memoization/cfg/SubgraphMap.java
modified: ../src/cd/profiler/Profile.java
modified: ../test/cd/test/TestSamplePrograms.java
modified: ../../notes/20150521.txt
这里我有一堆文件,我想将它们包含在不同的提交中。到目前为止,我所做的是做一堆 git add <pathspec>
,然后是相应的 git commit
。 <pathspec>
是让我恼火的地方。有没有类似下面的东西?
1 modified: assembly/main.debug.s
2 modified: ../src/cd/Config.java
3 modified: ../src/cd/memoization/cfg/SubgraphFinder.java
4 modified: ../src/cd/memoization/cfg/SubgraphMap.java
5 modified: ../src/cd/profiler/Profile.java
6 modified: ../test/cd/test/TestSamplePrograms.java
7 modified: ../../notes/20150521.txt
git magic 2,3,5 -m "My super simple commit"
示例回购:
我正在使用包含四个文件的示例存储库:a、b、c、d。
这里a
被跟踪、更改和上演; b
被跟踪、更改且未上演; c
在未跟踪和分阶段; d
只是未被追踪。
外部工具:git-number
When run without arguments, 'git number' runs 'git status' and attach a unique number for each line of filename printed by 'git status', and it will 'remember' this number-to-filename association. When run with arguments, like this:
$ git number <any git command> [one or more numbers or git options/args]
'git number' will run that and subtitute all the numbers to their equivalent filenames. Non-numeric argument are passed intact to git.
这适用于其他命令。
外部工具:SCM Breeze
SCM Breeze is a set of shell scripts (for bash and zsh) that enhance your interaction with git. It integrates with your shell to give you numbered file shortcuts, a repository index with tab completion, and many other useful features.
SCM Breeze 利用键盘快捷键和别名按编号处理 git 个文件:
Ctrl + x, c => git_add_and_commit
- 添加给定文件(如果有),然后提交暂存更改
Ctrl + x, Space => git_commit_all
- 提交所有内容
git add
:
$ ga 1
git diff
:
$ gd 2
git reset
:
$ grs 3
git commit
:
$ gco 4
使用 git add -i
的原生方式
git add -i
来自 Git reference:
-i
--interactive
Add modified contents in the working tree interactively to the index. Optional path arguments may be supplied to limit operation to a subset of the working tree. See “Interactive mode” for details.
您可以将此记为 -i
直观,因为界面非常直观。好吧,至少对硬核 Vim 用户来说是这样。
打开交互模式:
添加(暂存)跟踪文件:
添加一个未跟踪的文件:
查看变化:
如果您在添加过程中遇到困难,请使用空字符串点击 Return。
注: