[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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具