How can I stash only one of multiple changed files on my branch?
相关问题
- 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
You can also use
git stash save -p "my commit message"
. This way you can select which hunks should be added to stash, whole files can be selected as well.You'll be prompted with a few actions for each hunk:
Just in case you actually mean discard changes whenever you use
git stash
(and don't really use git stash to stash it temporarily), in that case you can use[NOTE]
That
git stash
is just a quicker and simple alternative to branching and doing stuff.To stash a single file use
git stash --patch [file]
.This is going to prompt:
Stash this hunk [y,n,q,a,d,j,J,g,/,e,?]? ?
. Just typea
(stash this hunk and all later hunks in the file) and you're fine.Since creating branches in Git is trivial you could just create a temporary branch and check the individual files into it.
Sometimes I've made an unrelated change on my branch before I've committed it, and I want to move it to another branch and commit it separately (like master). I do this:
Note the first
stash
&stash pop
can be eliminated, you can carry all of your changes over to themaster
branch when you checkout, but only if there are no conflicts. Also if you are creating a new branch for the partial changes you will need the stash.You can simplify it assuming no conflicts and no new branch:
Stash not even needed...
Quick Answer
For revert a specific changed file in git, you can do the following line:
Here is an actual example: