I have got changes in my staging area, and others not staged yet (some files have changes both in and out the staging area). I would like to invert the content of the staging area and the changes which are not staged. Does a shortcut exist in order to do that, without doing more complex actions like local side-branch commits, or diffs, or stashes [etc.]? Thanks.
相关问题
- Why does recursive submodule update from github fa
- Extended message for commit via Visual Studio Code
- Emacs shell: save commit message
- Can I organize Git submodules in a flat hierarchy?
- Upload file > 25 MB on Github
相关文章
- 请教Git如何克隆本地库?
- GitHub:Enterprise post-receive hook
- Git Clone Fails: Server Certificate Verification F
- SSIS solution on GIT?
- Is there a version control system abstraction for
- ssh: Could not resolve hostname git: Name or servi
- Cannot commit changes with gitextensions
- git: retry if http request failed
Here’s how I do it:
It can be typed out manually pretty fast, especially if you use Vim for commit messages:
Based on gtd's answer and the ability to script inverting the commits this is what I'm using now:
Posted on my blog here: http://blog.ericwoodruff.me/2013/12/inverting-git-index.html
There’s probably more than one way to do this, but I think I would take this approach – there’s currently no pre-built shortcut to this, but you could pretty easily write your own script to follow this process:
Generate a patch for the stuff that is currently in your working directory but not in your index yet (things you haven’t done
git add
for)Generate a patch for what you’ve already added to the index against your current
HEAD
Reset your index and working directory to your
HEAD
Apply your unstaged patch to both your working directory and your index, resulting in those changes being staged
Apply your staged patch against only your working directory
Depending on the exact nature of your changes, steps 4 and/or 5 may result in some merge conflicts that you need to resolve by hand, but I’m not sure there’s a clean way to completely avoid that possibility.
You could probably use
git stash
to accomplish steps 1 and 4 instead of the above commands, but I’m not sure that would really gain you anything…Also, you may want to review the man pages for the
git diff-*
andgit apply
commands first to see if there are other options that might make sense for you to use.This is what I use to solve this issue.
First
git reset
which will remove all the files from 'staging' to 'files not staged for commit'. The files that are in both 'staging' and 'files not staged for commit' will keep your most recent changes that are currently in your 'files not staged for commit'then
git add /path/to/file
the specific files you need to add to stagingNot exactly a short-cut, but it gets the job done
Inversely, After you
git reset
, you couldgit checkout /path/to/file
for the files that are currently 'not staged for commit' which you don't want to add to staging. This will remove specific files from 'not staged to commit'then run
git add .
which will add all files in 'not staged for commit' to 'staging' - whichever is easier for your situation