When you’re developing a project and suddenly a change comes along that needs to be changed and you don’t want to commit it, you can do this by making the project commit and then checkout to another branch. You can also stash the change and then checkout to another branch. There is no need for a commit, so there is one less commit.
- Git Stash temporary file
- Git Stash or Git Stash save ‘notes’ temporary changes
Git has already tracked the file, but only changed the code (not added the file). You can use the following two methods to temporarily save the changes
Git stash Git stash saveCopy the code
2, if there are new files added, then you need to add parameter -a(will temporarily store hidden files or files ignored by.gitnore) carefully use -u to temporarily store only untracked files
- add
-a
Parameters (git stash -a
或Git Stash Save -a
) careful - First,
git add .
And then use itgit stash
orGit Stash Save
To temporarily save the changes - add
-u
Parameters (git stash -u
orGit Stash Save -u
Recommended)
Note: The id in stash@{id} starts at 0 by default
git stash list
View all previously cachedstash
git stash list
-------------------------
stash@{0}: On masterOrder: masterOrder
stash@{1}: On devOrder: devOrder
Copy the code
git stash show
View a particularstash
Info which files are modified
git stash show
View a particularstash
Info which files are modified
git stash show stash@{0}
-------------------------
gulpfile.js | 1 +
1 file changed, 1 insertion(+)
Copy the code
Git stash show -p ‘stash@{0}
* 'git config --global user.email [email protected]' git config -- * 'git config --list or git Git config -- git config -- git config -- git config -- git config -- git config -- git config -- git config -- git config -- git config -- git config --global --unset user.name 'Deletes the global configurationCopy the code
git stash apply
Take out the staging areastash
But not instash list
Remove the
Stash stash apply stash@{1} stash the specified stashCopy the code
Git Stash drop Drops the stash stash
- If no stash is specified, the first stash stash is deleted by default
- Git stash drop stash@{1} Drops the specified stash
It Stash pop Removes the stash from the staging area
- Git stash pop Not specifying stash removes the first stash stash by default
- Git stash pop stash@{1} Takes out and deletes the specified stash
Git Stash clear Clears all stash lists
If you are using the Windows powershell command line in vscode, note that the ‘stash@{1}’ should be quoted when operating on a specified stash. Otherwise, you will have the following problems. You can use git bash or cmder to add it
git stash apply stash@{1}
----------------------
unknown option: -encodedCommand
Copy the code
Git tag label
In project versioning, the tag function is used whenever a release is released and a record is needed so that the release can be repackaged at a later time.
- ** Add label **
Git tag -a v1.1 -m "Release version" -a v1.1 -mCopy the code
- View all labels
git tag --list
Copy the code
- Submit the label to the remote server
Git push Origin -- Tags // Submit all tags to server git push Origin v1.1Copy the code
Git push Origin Master does not push tags to the server.
- ** Switches to a label **
git checkout [tagname]
When you switch to a tag, you are not in any branch, in a favorable state, and the version has not been rolled back. Please do not modify the tag again. You can create a branch based on this tag and submit it
- View information about a label
Git show v1.1Copy the code
- ** Delete the label **
Git tag - d v1.1Copy the code
- Delete the label of the remote server
Git push origin: refs/tag/v1.1Copy the code
Git undo changes
- I changed a bunch of files locally (without using Git to add them to staging) and wanted to abandon the changes.
Git checkout -- <filename> git checkout --.Copy the code
- Undo changes to files in the workspace. Only files that have not been added to the staging area will be undone. Only files that have been modified will be abandoned, and new and deleted files will not be abandoned
- A bunch of files have been added or deleted locally (not git added to staging area) and want to give up changes
git clean -f <filename>
Copy the code
- Removes locally added, modified, or deleted unadded files
- A bunch of files have been modified/added locally
git add
To the staging area, want to abandon the modification.
git reset [HEAD] <filename> git reset [HEAD] . Git restore -- passage <filename>Copy the code
- A git add & git commit has not yet been done
git reset commit_id
git reset --hard commit_id
Copy the code
- Undo git push to remote code (exercise caution)
First use in local warehouse
Git reset - hard [commit_id]Copy the code
Git reset - hard [commit_id]Copy the code
Reset the local repository to the version you want to undo, and then use
git push origin -f
Copy the code
Commit to enforce consistency between the remote and local repositories
- Revoke the COMMIT comment (modify the commit comment) last commit
Git commit -- amend-mCopy the code
Can override the last message to merge into a single commit