-1

How can a Git version control system (based on the git stash command) do:

  1. saving changes to the cache
  2. synchronize the cache through the repository with another computer
  3. modify the changes on another computer and make a commit there already?

I failed to implement

4
  • 6
    Is there a reason why you want to implement this with stash instead of real commits? Commented Nov 22, 2023 at 7:38
  • 1
    @Андрей, use a temporary branch. At the local repo: commit, push, reset soft to update the local index, delete the branch. At the remote: restore cache from the pushed branch, remove the branch. Commented Nov 22, 2023 at 7:54
  • The stash is not a cache system. And commits are not set in stone. Just commit and push, fetch from the other side, and reset the temp commit there. Commented Nov 22, 2023 at 8:16
  • Do yourself a favour and stop using stash and instead use temporary commits. None of the (many) shortcomings of stash applies to the scenario you describe when you use normal commits. Commented Nov 24, 2023 at 1:09

1 Answer 1

3

The stash entries are also commits. You can create a ref on the head of a stash entry and then publish it.

# Create a stash entry with a meaningful message git stash push -m "some description" # Create a branch or a tag or any ref on the newly created stash entry git branch stash_0 stash@{0} # Push the branch "stash_0" to the remote git push origin stash_0 # Pull the branch "stash_0" and apply the stash entry git fetch origin stash_0 git stash apply FETCH_HEAD 

If you insist on stashes, you can define a custom ref for such stash entries, so that they won't be confusing with regular branches and tags.

git push origin stash@{2}:refs/stashes/001 git push origin stash@{0}:refs/stashes/002 git fetch origin refs/stashes/001 && git stash apply FETCH_HEAD git fetch origin refs/stashes/002 && git stash apply FETCH_HEAD 
Sign up to request clarification or add additional context in comments.

1 Comment

@Андрей : to illustrate that "stash entries are also commits": check git log --oneline --graph stash, git log --oneline --graph stash@{1} ...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.