[Git] Stashing -- Ex
GIT STASH
You're not quite ready to commit what you're working on, but need to make a quick fix to master. Fear not, just stash
your current changes so you can switch to master quick.
git stash save
GIT STASH LIST
You just finished making those quick changes to master. You're now ready to resume your work on the feature you had started on before you had to fix master. Let's first list all the stashes to make sure we get the right one.
git stash list
GIT STASH APPLY
Great! As you can see, your stash is in the stash list. Let's apply the stash so you can get back to work.
git stash apply
GIT STASH DROP
Ok, so now that you have all your stashed changes back, let's clean up the stash list. There's only one stash; go ahead and drop it.
git stash drop
CONFLICTS I
You came back from master and resumed working on your feature, when you realize that you forgot to apply your saved stash. Go ahead and apply it now.
git stash apply
CONFLICTS II
Uh oh! There was a conflict when trying to apply your previous stash. It's no problem, you were just trying things anyway. Go ahead and do a hard
reset back to the last commit.
git reset --hard HEAD
GIT STASH POP
Now that you have the file reset, use the pop
command to apply and delete the stash at the same time.
git stash pop
KEEPING THE INDEX
You need to swap branches again, but this time some of your changes are ready to be committed. Stash all the unstaged changes, but leave the staged changes intact so they can be committed afterwards.
git stash save --keep-index
INCLUDE UNTRACKED
Wow, there are so many small fixes on master today! You really need to stash some more changes, but it doesn't seem to be working on these untracked files you just created. Try using the --include-untracked
option to stash all those new files.
git stash save --include-untracked
LIST OPTIONS
You've been stashing stuff all day since you keep having to make small quick fixes to master. Now you have a bunch of stashed changes and you're not sure which one you need to apply. You could look through them all one by one, or you could use the --stat
option to list information about each stash. Give that a try.
git stash list --stat
STASH DETAILS
You now have a list of stashes that are showing you more information, and you think you may have spotted the stash that you need. Take a more detailed look at the stash@{2}
stash with the --patch
option.
git stash show stash@{2} --patch
diff --git a/poodles.rb b/poodles.rb index 28cab25..259cbf3 100644 --- a/poodles.rb +++ b/poodles.rb @@ -1,15 +1,9 @@ class Poodle < Dog + include FleaCollar + def size :small end - def bugs - fleas? - end - private - - def fleas? - true - end end diff --git a/unicorn.rb b/unicorn.rb index b7f84f8..5578e78 100644 --- a/unicorn.rb +++ b/unicorn.rb @@ -4,6 +4,6 @@ class Unicorn < Horse end def sparkle! - Glitter.on + Glitter.color(:random).on end end
STASH MESSAGE
You're halfway through a large feature. Your team has decided that they want you to deploy what you have so far, but you have a smaller unfinished feature that isn't ready to be committed yet. Go ahead and stash your current changes with the message Added groom method
, so you know which stash has your changes.
git stash save "Added groom method"
STASH BRANCHING
Now that you've deployed the main part of your feature, you need to finish up what is left. Create a new branch named 'poodle' and apply your most current stash all in one command.
git stash branch poodle
相关文章
- git命令-切换分支
- 在局域网搭建一个带 web 操作页面的 git 版本服务器 - Gitlab
- git 报错Git fatal: Unknown index entry format xxxxx的错误解决方法
- Webstorm或IDEA上传项目到git
- git拉取代码如何解决冲突_Git工具-git pull拉取代码时冲突的解决办法[通俗易懂]
- Git版本控制入门
- 彻底解决 git push 的【pack exceeds maximum allowed size】
- 通过 GitExtensions 来使用 Git 子模块功能
- 【Git】Git 基础命令 ( Git 版本库概念 | 创建版本库 git init | 克隆版本库 git clone )
- 【Git】Git 版本管理 ( 补充提交版本 git commit --amend | 版本库提取文件 git checkout -- filename | 删除文件 git rm )
- 【错误记录】Git 使用报错 ( error: Cannot delete branch ‘dev‘ checked out at ‘D:/Git/git-learning-course‘)
- git clone —— 从github官网下载自己的项目到本地(同步远程仓库)详解程序员
- 使用Git来升级你的Linux系统(git升级linux)
- git和春天、Linux和Git一起收获成功(springlinux)
- 搭建Linux服务器,实现Git共享(linux搭建git服务器)
- 安装linux下Git安装指南(linux下git)
- 如何在Linux上轻松部署Git?(linux下部署git)
- 从Git合集进入Redis集群的新路(redis集群git合集)