Published 3月 12, 2024 by with 0 comment

Git Lab 05 - Stashing and Cleaning


When you’ve been working on part of your project, things are in a messy state and you want to switch branches for a bit to work on something else.
The problem is, you don’t want to do a commit of half-done work just so you can get back to this point later. 
The answer to this issue is the git stash command.


Lab 5.1: Stashing Your Work (Untracked file)

git-stash - Stash the changes in a dirty working directory away

Example Code:
$ touch lab5-1
$ git status
$ git stash save -u lab5-1 -m "stash lab5-1"
$ git status
$ git stash list
$ git stash show
$ git stash apply
$ git add lab5-1
$ git commit -m "add lab5-1"


Lab 5.2: Stashing Your Work (Tracked file)

Example Code:
$ touch lab5-2
$ git add lab5-2
$ git status
$ git stash save lab5-2 -m "stash lab5-2"
$ git status
$ git stash list
$ git stash show
$ git stash apply
$ git status
$ git commit -m "add lab5-2"


Reference:
1. Git - Commands Reference

2. Git Tools - Stashing and Cleaning


最初發表 / 最後更新: 2024-03-12 / 2024-03-12

0 comments:

張貼留言