admin管理员组文章数量:1406949
I need a solution to snapshot a dirty Git repo and make it available remotely. I want to use Git instead of rsync since we need versioning, deduplication and speed and the users are already using Git.
I need a non-intrusive script that creates a commit and pushes it to the upstream, all without any disruption of the current state of the repo/workdir/index
.
Requirements:
- Script returns a commit SHA that's available remotely (e.g. GitHub).
- Another user or system can checkout that commit SHA and get the same working copy as the first user.
- The state of the user's local repo is not disrupted in any way (working copy files, active branch, index etc)
Implementation idea: The script creates a separate index, stages all working copy files, commits the files, pushes the commit upstream and returns the SHA.
How can I implement this? The hard part for me is no disrupting the active branch and index.
Can git stash
be used to accomplish this?
Or maybe something like this:
git_dir=$(git rev-parse --git-dir)
tmp_index=$(mktemp)
cp "$gitdir/index" "$tmp_index"
GIT_INDEX_FILE="$tmp_index" git add --all # Is this enough to capture the current state of the working directory?
GIT_INDEX_FILE="$tmp_index" git commit --message stash ??? How to tell git comit to not change any branch and return new SHA?
GIT_INDEX_FILE="$tmp_index" git push origin ???:??? How to push commit to remote without creating a remote branch?
Update:
It looks like git stash create
does almost everything I need: Non-intrusive commit from a current working directory state.
Is t true that git does not allow me to just push a commit to remote, and I must push it to a remote branch?
Update2
It looks like the ability to do git stash create --include-untracked
was lost during the transition of git stash from shell to builtin.
Last version of stash that was shell-only: .sh
Last version of stash.sh with full save support without helper: .sh
A non-destructive do_stash_create
with support for untracked files still exists in C, but all functions that expose it are either destructive or don't expose --include-untracked
.
本文标签:
版权声明:本文标题:archive - Git: "Auto-stasher": Capture and push the current state of the working directory in a non-intrusive 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744880515a2630179.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论