Skillfully use git stash to temporarily store code locally to solve conflicts & & temporarily store files

Time:2021-12-4

Staging files & & common commands

(1)git stash save “save message”: during storage, add notes to facilitate search. Only git stash can be used, but it is not easy to identify during search.

(2)git stash list : see what storage is stash

(3)git stash show: displays the changes made. The first storage is shown by default. If you want to display other storage, add stash @ {$num}, such as the second git stash show stash @ {1}

(4)git stash show -p: display the changes of the first storage. If you want to display other storage, command: git stash show stash @ {$num} – P, for example, the second: git stash show stash @ {1} – P

(5)git stash apply: applies a storage, but does not delete it from the storage list. The first storage is used by default, that is, stash @ {0}. If you want to use other storage, GIT stash apply stash @ {$num}, such as the second: git stash apply stash @ {1}

(6)git stash pop: the command restores the previously cached working directory, deletes the corresponding stash in the cache stack, and applies the corresponding modification to the current working directory. The default is the first stash, that is, stash @ {0}. If you want to apply and delete other stash, the command: git stash pop stash @ {$num}, for example, apply and delete the second: git stash pop stash @ {1}

(7)git stash drop [email protected]{$num}: discard the stash @ {$num} store and delete it from the list

(8)git stash clear: delete all cached stash

Resolve code conflicts locally

1. Git stash temporary file
2. Git pull pull pull the latest code
3. Git stash pop recover temporary files
4. Conflict resolution
5. Submit code

Temporarily storing some files for local use without submitting

1. Add files you don’t want to back up (for example: git add, file1.js, File2. JS)
2. Call git stash – keep index. Only those files that have not been added will be backed up.
3. Call git reset to cancel the backup of the added file and continue your work.