Home  >  Article  >  Computer Tutorials  >  Detailed explanation of the common git command stash.

Detailed explanation of the common git command stash.

WBOY
WBOYforward
2024-02-18 16:57:21459browse

Detailed explanation of the common git command stash.

In Git,
stash is a commonly used command to temporarily save changes to the current working directory so that you can switch branches or apply other changes without losing current modifications. The following is a detailed explanation of the
stash command:

  1. git stash save "message"

    • This command saves the changes to the current working directory to a new stash.
    • "message"The parameter is optional and is used to provide a short descriptive message to explain the contents of the stash.
  2. git stash list

    • This command lists all stash saved in the current warehouse.
    • Each stash has an identifier and corresponding description message.
  3. git stash apply stash@{n}

    • This command applies the specified stash and applies the saved changes to the current branch.
    • stash@{n}The parameter indicates the identifier of the stash to be applied, where
      n is the index number of stash.
  4. git stash pop

    • This command applies the latest stash and applies the saved changes to the current branch.
    • At the same time, it will also remove the applied stash from the stash list.
  5. git stash branch <branch_name></branch_name>

    • This command will create a new branch and apply the specified stash to the new branch.
    • <branch_name></branch_name>The parameter is the name of the new branch.
  6. git stash drop stash@{n}

    • This command discards the specified stash and deletes it from the stash list.
    • stash@{n}The parameter indicates the identifier of the stash to be discarded.
  7. git stash clear

    • This command will delete all saved stash and clear the stash list.

Использование команды
stash может быть очень полезно при обработке нескольких переключателей ветвей или сохранении временных изменений. Вы можете использовать команду
stash, чтобы сохранить изменения в текущем рабочем каталоге, переключиться на другие ветки или применить другие изменения, а затем вернуться и применить ранее сохраненный тайник. Это гарантирует, что ваш рабочий каталог всегда будет чистым и никакие важные изменения не будут потеряны.

The above is the detailed content of Detailed explanation of the common git command stash.. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:mryunwei.com. If there is any infringement, please contact admin@php.cn delete