https://github.com/s3rvac/git-edit-index
A git command that opens an editor to stage or unstage files
https://github.com/s3rvac/git-edit-index
git index python staging unstaging
Last synced: about 1 year ago
JSON representation
A git command that opens an editor to stage or unstage files
- Host: GitHub
- URL: https://github.com/s3rvac/git-edit-index
- Owner: s3rvac
- License: mit
- Created: 2015-05-23T10:40:57.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2025-04-01T17:15:21.000Z (about 1 year ago)
- Last Synced: 2025-04-08T03:02:17.944Z (about 1 year ago)
- Topics: git, index, python, staging, unstaging
- Language: Python
- Homepage:
- Size: 156 KB
- Stars: 9
- Watchers: 4
- Forks: 3
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
git-edit-index
==============
[](https://github.com/s3rvac/git-edit-index/actions/workflows/tests.yml?query=branch%3Amaster)
[](https://coveralls.io/github/s3rvac/git-edit-index?branch=master)
[](https://pypi.python.org/pypi/git-edit-index)
This command represents a faster alternative to `git add -i` or `git gui`. It
allows you to stage or unstage files from the index in an editor, just like
when you perform an interactive rebase.

For example, let's assume you have the following three modified files (`git
status --short`):
M path/to/file1
M another/path/to/file2
M yet/another/path/to/file3
After running `git edit-index`, an editor will show up with the above output.
To stage (add) the first two files, simply change the text to
A path/to/file1
A another/path/to/file2
M yet/another/path/to/file3
You can also unstage (`reset`) files, add only parts of files (`add -p`), or
delete files (`rm`).
Requirements
------------
The script requires Python 2.7 or Python >= 3.8. Both CPython and PyPy
implementations are supported.
Note: The script might work even in older Python 3 releases, but this is not
guaranteed.
Installation
------------
Either install the script from [Python Package
Index](https://pypi.python.org/pypi/git-edit-index) (PyPI) with
[pip](http://www.pip-installer.org/):
$ pip install git-edit-index
or install it manually by performing the following two steps:
* Put the
[`git-edit-index`](https://raw.githubusercontent.com/s3rvac/git-edit-index/master/git-edit-index)
script to a directory that is in your `$PATH`.
* Ensure that the script is executable (`chmod a+x git-edit-index`).
Usage
-----
Run `git edit-index` to display an editor with the current index. In it, you
can stage or unstage files from the index simply by changing their status:
* To stage a modified or deleted file, change its status from `M` or `D` to
`A`. This runs `git add FILE`. If you use `P` instead of `A`, it will run
`git add -p FILE` instead.
* To unstage a modified file, change its status from `A` to `M`. This runs `git
reset FILE`.
* To unstage a deleted file, change its status from `A` to `D`. This also runs
`git reset FILE`. If you use `P` instead of `D`, it will run `git reset -p
FILE` instead.
* To add an untracked file, change its status from `?` to `A`. This runs `git
add FILE`.
* To stop tracking of a file, change its status to `?`. This runs `git rm
--cached FILE`.
* To add an ignored file, change its status from `!` to `A`. This runs `git add
-f FILE`.
* To delete an untracked or ignored file, remove the line with the file. This
deletes the file by using the operating system's file-deletion facilities.
* To revert changes done to a file since the last commit, remove the line with
the file. This runs `git checkout FILE` (if the file is staged, it first runs
`git reset FILE`).
The status is case-insensitive, e.g. both `A` and `a` stage the given file
(lower-case letters are easier to type).
As with `git status`, ignored files aren't being shown by default,
instead the flag `--ignored` has to be set.
Selecting an Editor
-------------------
The editor can be specified either by setting
[core.editor](http://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration#Basic-Client-Configuration)
in your Git config:
git config --global core.editor "gvim -f"
or by setting the `EDITOR`, `VISUAL`, or `GIT_EDITOR` environment variable in
your shell:
export EDITOR="gvim -f"
See the VARIABLES section in the [manual pages for
`git-var`](http://git-scm.com/docs/git-var) for the used order of preference.
Using an Alias
--------------
Of course, instead of typing `git edit-index`, you can setup a [git
alias](https://git-scm.com/book/tr/v2/Git-Basics-Git-Aliases):
git config --global alias.ei edit-index
Then, all you have to do is to type git ei.
Configuration Options
---------------------
The command supports the following configuration options via [Git's
configuration
system](https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration).
### git-edit-index.onEmptyBuffer [ask|act|nothing]
What should be done when the editor buffer is empty (i.e. all lines were
deleted). Possible values:
* `ask`: Ask the user by showing him or her a `y/N` prompt. This is the default
behavior of the command since version `0.5`.
* `act`: Reflect the changes, without asking. This was the default behavior of
the command until version `0.5`.
* `nothing`: Do not reflect any changes, without asking. This corresponds to
the default behavior of many other Git commands.
Default: **ask**.
Limitations
-----------
* Only the following statuses are currently supported:
* `A`: Added file (staged).
* `D`: Deleted file (not staged).
* `M`: Modified file (not staged).
* `?`: Untracked file.
* `!`: Ignored file.
* Working with files having merge conflicts (status `U`,
[#5](https://github.com/s3rvac/git-edit-index/issues/5)), renamed files
(status `R`, [#6](https://github.com/s3rvac/git-edit-index/issues/6)), copied
files (status `C`, [#7](https://github.com/s3rvac/git-edit-index/issues/7)),
and partially staged files (status `MM`,
[#8](https://github.com/s3rvac/git-edit-index/issues/8)) is currently not
supported.
Development
-----------
To run tests, install [pytest](https://docs.pytest.org/) and run
```
make tests
```
To perform linting checks, install [flake8](https://flake8.pycqa.org/) and run
```
make lint
```
License
-------
Copyright (c) 2015 Petr Zemek (s3rvac@petrzemek.net) and contributors.
Distributed under the MIT license. See the
[`LICENSE`](https://github.com/s3rvac/git-edit-index/blob/master/LICENSE) file
for more details.