之前就记得其实 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
会报错),不过基本够我用了。
后续有更新的话会更新在 这里
![]() | 1 quqiu 341 天前 为啥不直接开临时分支搞? |
![]() | 2 liu731 PRO 为啥要分开,2 台电脑操作相同 git 不就好了吗(比如放在 NAS 里面)? |
![]() | 3 jybox OP |
4 qwell 341 天前 一边 commit ,另一边拉取再 reset 呢 |
6 minglanyu 341 天前 蛮小众的场景 不过确实属于 git 高级玩家了 |
![]() | 7 zmxnv123 341 天前 我也有类似的问题,仅 sync git stash 不够用啊,如果一台电脑本地提交了没推远程另一台电脑就废了。后来我直接 remote develop 了,但是网速是个问题 |
![]() | 8 wjfz 341 天前 这种情况我一般都是先 push 在另一台电脑 pull 、git reset HEAD~,修改完之后再 git push -f |
9 jadehare 341 天前 commit 同步了再 rebase ? |
10 nebkad 341 天前 非常合理的软件需求分析和功能设计,写好了喊我试试 |
![]() | 11 yh7gdiaYW 341 天前 我是用一个 git 和一个 svn 实现了差不都的效果 |
![]() | 12 webcape233 341 天前 via iPhone 我是家里两个电脑 syncthing...啥也不用管自己用不 |
13 mengzhuo 341 天前 push 到一个无头分支,然后 cherry-pick 过来就行 |
![]() | 14 zmxnv123 341 天前 @webcape233 syncthing 同步不了 git 仓库,尤其是频繁修改的情况下 |
![]() | 16 hzzhzzdogee 227 天前 cool |