zl程序教程

您现在的位置是:首页 >  工具

当前栏目

[Git] Stashing -- Ex

Git -- EX
2023-09-14 08:59:21 时间

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