乐闻世界logo
搜索文章和话题

什么是“git stash”?

1个答案

1

git stash is a very useful feature in the Git version control system. It allows you to temporarily save changes in your working directory and staging area, and then restore a clean working directory. This enables you to switch to other branches to work on different tasks and return later to continue your previous work.

For example, suppose you are developing a new feature on the feature-A branch and suddenly need to fix an urgent bug on the master branch. However, your current work is not yet ready for a commit, and you don't want to commit a half-finished change. In this case, you can use git stash to save your current progress. The command is:

bash
git stash

This saves your changes and restores your working directory to a clean state before modifications. Then you can safely switch to the master branch to fix the bug. After fixing the bug, you can switch back to the feature-A branch and use the following command to restore your previous work:

bash
git stash pop

This reapplies your previous changes, allowing you to continue your work. This feature is very useful when handling multiple tasks and frequently switching branches.

2024年7月15日 10:31 回复

你的答案