In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to apply the stash command of git". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to apply the stash command of git".
Why is git stash important?
The first thing to understand is why it is important to temporarily store changes in Git. Assume that Git does not have a command to temporarily store changes. When you are working in a warehouse with two branches (An and B), the two branches have forked for some time and have different heads. When you are working on some files in Branch A, your team asks you to fix a bug in Branch B. You quickly save your changes to Branch A (but do not commit) and try to check out Branch B with git checkout B. Git immediately aborts the operation and throws an error: "your local changes to the following files will be overwritten by the check out."... please submit your changes or save them temporarily before switching branches. "
In this case, there are several ways to enable branch switching:
Create a commit in branch A, commit and push your changes to fix the errors in B, then check out An again, and run git reset head ^ to restore your changes.
Manually retain changes in files that are not tracked by Git.
The second method is a bad idea. The first approach, while traditional, is inflexible because saving changes to unfinished work is treated as a checkpoint rather than a patch in progress. This is the scenario in which git stash is designed.
Git stash saves uncommitted changes locally, allowing you to make changes, switch branches, and other Git operations. Then, when you need it, you can reapply these stored changes. Temporary storage is local and will not be pushed remotely by git push.
How to use git stash
Here is the order to follow when using git stash:
Save the changes to branch A.
Run git stash.
Check out branch B.
Fix the error in branch B.
Submit and (optionally) push to remote.
View Branch A
Run git stash pop to retrieve your temporary changes.
Git stash stores your changes to the working directory locally (in your project's .git directory, to be exact / .git / refs/stash) and allows you to retrieve these changes when needed. It is convenient when you need to switch between different contexts. It allows you to save changes that you may need later, and is the fastest way to keep your working directory clean while keeping your changes intact.
How to create a temporary store
The easiest command to temporarily store your changes is git stash:
$git stashSaved working directory and index state WIP on master; d7435644 Feat: configure graphql endpoint
By default, git stash stores (or "staging") uncommitted changes (staged and unstaged files) and ignores untracked and ignored files. Usually, you don't need to temporarily save untracked and ignored files, but sometimes they may interfere with other things you need to do in the code base.
You can use additional options to let git stash handle untracked and ignored files:
Git stash-u or git stash-- includ-untracked stores untracked files.
Git stash-an or git stash-- all stores untracked files and ignored files.
To store a specific file, you can use the git stash-p or git stash-patch command:
$git stash-- patchdiff-- git a/.gitignore b/.gitignoreindex 32174593..8d81be6e 100644 Mustang-dependencies node_modules/. Gitignorestores + bbin.gitignorewriting @-3 dependencies node_modules/ 7 @ @ # dependencies node_modules/ / .pnp.js # testing (1) Stash this hunk. List your temporary deposit
You can use the git stash list command to view your temporary storage. Temporary storage is saved in last-in, first-out (LIFO) mode:
$git stash liststash@ {0}: WIP on master: d7435644 Feat: configure graphql endpoint
By default, the staging is displayed at the top of the branch and submission where you created it, marked as WIP. However, when you have multiple temporary stores, this limited amount of information does not help because it is difficult to remember or check their contents separately. To add a description to the staging, use the command git stash save:
$git stash save "remove semi-colon from schema" Saved working directory and index state On master: remove semi-colon from schema $git stash liststash@ {0}: On master: remove semi-colon from schemastash@ {1}: WIP on master: d7435644 Feat: configure graphql endpoint search temporary changes
You can use the git stash apply and git stash pop commands to reapply temporary changes. Both commands reapply the changes in the latest staging (that is, stash@ {0}). Apply reapplies the changes, while pop reapplies the staged changes to the working copy and removes them from the staging. If you do not need to reapply the temporarily saved changes again, pop is preferred.
You can select the storage you want to pop up or apply by passing the identifier as the last parameter:
$git stash pop stash@ {1}
Or
$git stash apply stash@ {1} Clean up staging
It is a good habit to delete temporary storage that is no longer needed. You must do this manually with the following command:
Git stash clear clears the list by deleting all temporary repositories.
Git stash drop removes a specific staging from the staging list.
Check for temporary differences
The command git stash show allows you to view a temporary difference:
$git stash show stash@ {1} console/console-init/ui/.graphqlrc.yml | 4 +-console/console-init/ui/generated-frontend.ts | 742 +-console/console-init/ui/package.json | 2 +-
To get more detailed differences, you need to pass the-- patch or-p flag:
$git stash show stash@ {0}-- patchdiff-- git a/console/console-init/ui/package.json b/console/console-init/ui/package.jsonindex 755912b97..5b5af1bd6 100644 Fuyu-a name consoleMerit: "my-usepatternfly-2", "version": "version": "0.1.0" "private": true, "proxy": "http://localhost:4000"diff-git a/console/console-init/ui/src/AppNavHeader.tsx b/console/console-init/ui/src/AppNavHeader.tsxindex a4764d2f3..da72b7e2b 100644 Mustang-a css from @ 9 + 9 @ import {css} from" @ patternfly/react-styles Interface IAppNavHeaderProps extends PageHeaderProps {- toolbar?: React.ReactNode;- avatar?: React.ReactNode;+ toolbar?: React.ReactNode;+ avatar?: React.ReactNode;} export class AppNavHeader extends React.Component {render () is checked out to a new branch
You may encounter a situation where a branch disagrees with the changes in your temporary storage, which will cause a conflict when you try to reapply the temporary storage. A simple workaround is to use the git stash branch command, which creates a new branch based on the submission when the staging was created and pops up the changes in the staging:
$git stash branch test_2 stash@ {0} Switched to a new branch 'test_2'On branch test_2Changes not staged for commit: (use "git add..." to update what will be committed) (use "git restore..." to discard changes in working directory) modified: .graphqlrc.ymlmodified: generated-frontend.tsmodified: package.jsonno changes added to commit (use "git add" and/or "git commit-a") Dropped stash@ {0} (fe4bf8f79175b8fbd3df3c4558249834ecb75cd1) without disturbing the temporary reference log
In rare cases, you may need to create a temporary store while maintaining the integrity of the temporary reference log (reflog). These situations may occur when you need a script to temporarily store as an implementation detail. This can be done through the git stash create command; it creates a staging entry and returns its object name without pushing it to the staging reference log:
$git stash create "sample stash" 63a711cd3c7f8047662007490723e26ae9d4acf9
Sometimes, you may decide to push staging entries created through git stash create to the staging reference log:
$git stash store-m "sample stash testing.."63a711cd3c7f8047662007490723e26ae9d4acf9" $git stash liststash @ {0}: sample stash testing.. Thank you for your reading, the above is the content of "how to apply the stash command of git". After the study of this article, I believe you have a deeper understanding of how to apply the stash command of git, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.