The use and attention points and application scenarios of git stash

 Application scenario: During the development process, friends may encounter that when developing a new page, the boss asks to fix bugs on other branches. At this time, it is necessary to switch branches, but the new page has not yet been developed. Directly switching branches will Reporting an error, submitting the code directly will leave a meaningless submission message in the code base, so we can use git status to temporarily store the branch code

Introduce the commonly used git stash commands

  1. git stash or git stash save 'saved description' //Temporarily save the modified content or temporarily save and add description information for easy search
  2. git stash list // view all the contents of the current stash
  3. git stash pop//Apply a certain store (the first one by default), which is equivalent to git stash pop stash@`{0`} and delete this record in the stash library. git stash pop stash@`{1`} apply the second record and delete
  4. git stash apply//Apply a certain storage (the first one by default), which is equivalent to git stash apply stash@`{0`} but does not delete the records in the stash repository. git stash apply stash@`{1`} applies the second record
  5. git stash drop //Delete a storage (the first one by default), which is equivalent to git stash drop stash@`{0`} to delete the first record in the stash repository. git stash drop stash@`{1`} deletes the second record
  6. git stash clear // Clear the records of the stash library
  • Note: git stash can only temporarily store files that have been managed by git at that time. If it is a newly created file, you need to use git add xxx.txt to add the file to the temporary storage area of ​​git first, and then use git stash operation, the code is temporarily stored
  • //正常一个完整使用git stash的代码段
    
    git status // 查看当前修改的文件,看看是否有新建的文件
    
    git add 新建的文件名 //将新建的文件添加到git管理中
    
    git stash list // 查看stash库
    
    git stash save '修改的内容' // 已这个描述保存到stash库中
    
    git stash list // 对比刚刚查询的,查看stash库中是否存在暂存的数据
    
    git status // 此时的文件状态是干净的
    
    git stash pop stash@`{0`} // 将第一个暂存的数据恢复到代码中,并删除stash库中的记录
    
    git status // 此时的文件状态已恢复

Guess you like

Origin blog.csdn.net/weixin_42627850/article/details/129789109