I often encounter the following scenario:
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
Here I have a bunch of files and I want to include them in different commits. What I do so far is to do a bunch of git add <pathspec>
followed by a respective git commit
. The <pathspec>
is what annoys me. Is there something like the following?
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"
Add only one file, or one part of the changed file: git add README.md. Commit the first set of changes: git commit -m "update the README to include links to contributing guide" Add another file, or another part of the changed file: git add CONTRIBUTING.md.
Enter git add --all at the command line prompt in your local project directory to add the files or changes to the repository. Enter git status to see the changes to be committed.
Add files to the staging area by using the "git add" command and passing necessary options. Commit files to the local repository using the "git commit -m <message>" command. Repeat.
The git add command adds a change in the working directory to the staging area. It tells Git that you want to include updates to a particular file in the next commit. However, git add doesn't really affect the repository in any significant way—changes are not actually recorded until you run git commit .
I'm using an example repo with four files: a, b, c, d.
Here a
is tracked, changed and staged; b
is tracked, changed and not staged; c
in untracked and staged; d
is just untracked.
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.
This is available with other commands.
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 utilizes keyboard shortcuts and aliases to work with git files by number:
Ctrl + x, c => git_add_and_commit
- add given files (if any), then commit staged changes
Ctrl + x, Space => git_commit_all
- commit everything
git add
:
$ ga 1
git diff
:
$ gd 2
git reset
:
$ grs 3
git commit
:
$ gco 4
git add -i
git add -i
From 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.
You can remember this as -i
ntuitive, because the interface is really intuitive. Well, at least to hardcore Vim users.
Opening the interactive mode:
Adding (staging) a tracked file:
Adding an untracked file:
See the changes:
If you're stuck in the middle of adding, hit Return with an empty string.
Note:
If you're confused with the appearance and coloring: I've been using iTerm2 + zsh + oh-my-zsh.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With