Git Lecture 9 Git stash temporarily stores messages

git stashis a command used in Git to temporarily save uncommitted changes. It can help you save the changes in the current working directory so that you can restore them later when switching branches or dealing with urgent tasks.

git stashThe usage method is as follows:

  1. When you want to stage the current changes, run the following command:

    git stash save "message"
    

    Optionally, you can provide a short descriptive message identifying what is being staged this time. This is useful for finding or distinguishing between different stages later.

    For example:

    git stash save "Work in progress on feature X"
    
  2. Git will save the current changes to a new stash stack and restore your working directory to the state of the last commit.

  3. When needed, you can restore your staging content with the following command:

    • If you only have a staging change, you can run:

      git stash apply
      

      This will restore the most recent staging contents to your working directory. But that scratch will still remain on the storage stack.

    • If you have multiple staged changes, you can specify an index to choose which stage to restore. Run the following command:

      git stash apply stash@{
              
              <index>}
      

      Replace <index>with the index number of the staged content you want to restore. Index numbers start at 0 and represent the latest scratch contents.

    • If you want to remove the staging content from the storage stack after restoring it, you can use dropthe command:

      git stash drop stash@{
              
              <index>}
      

      This will permanently delete the staged content at the specified index number.

    • If you want to restore the staging content while removing it from the storage stack, you can use popthe command:

      git stash pop
      

      This restores the most recent staging and removes it from the storage stack.

Additionally, you can use git stash listthe command to view all scratch contents in the storage stack, along with their index numbers and associated messages.

git stash list

Hope this detailed explanation can help you understand git stashhow to use the command

Guess you like

Origin blog.csdn.net/huanglu0314/article/details/131157349