之前就记得其实 stash 也是一个特殊的 commit ,可以被 push 到远程仓库,于是写了两个 alias (在 ~/.gitconfig
里):
[alias]
wips = !(git stash -u | grep -qv 'No local changes to save' || (echo 'No local changes to save' && false)) && git stash show stash@{0} && (git push origin stash@{0}:refs/stashes/wip || (git stash pop && false)) && git stash drop -q
wipl = !git fetch origin refs/stashes/wip && git stash apply FETCH_HEAD && git push -qd origin refs/stashes/wip
使用时在需要暂存的设备上运行 git wips
( Working In Progress Save )
$ git wips
2019/12.bean | 2 --
2020/01.bean | 2 +-
2024/07.bean | 6 ++--
2024/08.bean | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2024/09.bean | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
2024/10.bean | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
2024/11.bean | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
main.bean | 3 ++
8 files changed, 369 insertions(+), 6 deletions(-)
Enumerating objects: 24, done.
Counting objects: 100% (24/24), done.
Delta compression using up to 12 threads
Compressing objects: 100% (15/15), done.
Writing objects: 100% (16/16), 3.30 KiB | 3.30 MiB/s, done.
Total 16 (delta 10), reused 0 (delta 0), pack-reused 0 (from 0)
To infinity:repos/accounting
* [new reference] stash@{0} -> refs/stashes/wip
然后可以在其他配置了同一远程仓库的设备上运行 git wipl
( Working In Progress Load )
$ git wipl
From infinity:repos/accounting
* branch refs/stashes/wip -> FETCH_HEAD
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: 2019/12.bean
modified: 2020/01.bean
modified: 2024/07.bean
modified: main.bean
Untracked files:
(use "git add <file>..." to include in what will be committed)
2024/08.bean
2024/09.bean
2024/10.bean
2024/11.bean
no changes added to commit (use "git add" and/or "git commit -a")
过程就是从当前的工作区创建一个 stash ,推到远程一个叫 stashes/wip
的特殊 ref 上,再从另外的设备上拉取并删除。目前版本很简单,一次只能存在一个 stash (重复运行 git wips
会报错),不过基本够我用了。
后续有更新的话会更新在 这里
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.