When doing git stash 2 commits are created. One is referenced by the stash ref and has 2 parent commits. One parent is the index of where we did the stash. The other parent has the actual contents of what we stashed.
Why are 2 commits needed for the stash? It seems to me that only 1 was sufficient. I.e. just make stash ref to the commit that has the actual contents.
Would this not work?
Why does git stash creates 2 commit objects? Seems like 1 was adequate
180 views Asked by Jim At
1
There are 1 answers
Related Questions in GIT
- problem to push files on a repository git
- diff3 output in git conflict style, including mergeable hunks
- Git Not In Sync with Local Branch
- Setting up the version control of .dotfiles while the .config is connected to a forked repo
- How to fix overriding the main branch in Git?
- I can't add text to "Message" in VS Code when committing to Git
- How can i redirect pull request from main branch to another branch
- Xcode commits (possibly outside of any branch) disappeared, how to get them back?
- Git/TortoiseGit : how to apply ONLY the changes from ONE commit from branch A, to branch B?
- How can I reintroduce username an password on git using fedora?
- GIT SKIP EMPTY DIRECTORIES
- Git smudge run once per checkout or per commit?
- I can't find ~/.profile or ~/.bashrc in C:/Users/<user>/.ssh folder
- Set environment variable during push for GitHub Actions
- Android WebRTC compile
Related Questions in GIT-COMMIT
- How to amend last commit without losing commit tag
- Why some pull requests in GitHub have no commit list?
- Why aren't my git commits able to be signed
- Git update commit author on push event
- Create Pull Request Excluding Old Commits on bitbucket
- Error: Corrupted Git Object Files - Unable to Commit Changes
- Git feature branch dragged on too long
- Log a template message every time I commit in Git
- how to remove a renamed file from last git commit?
- why all previous commits got pushed again to the new branch?
- Can I make Xcode switch to Project navigator after a Commit completes?
- UNABLE TO COMMIT CHANGES FROM ECLIPSE TO GITHUB
- Why is the difference in commits of two branches is just stacking up when being merged? How to resolve?
- How to remove specific pull request from the git branch?
- Git - Merging from a PR overwrites previous commits leaving no history, why is this happening?
Related Questions in GIT-STASH
- Bogus Git error message... can't fix or work around it
- Git stash pop - lost untracked files
- How can I copy the Sourcetree stashes from old PC to a new one?
- Git move latest commit on a branch to stash
- git: recover untracked files after git stash - git stash apply
- Is there a way I can intentionally cause a merge conflict with a file inside my stash?
- `git stash apply --index` fails with `error: No valid patches in input` on one machine
- A one liner for stashing and simultaneously naming untracked changes and files using git stash
- Pop conflicting Git stash while keeping stash index
- git stash show -p: hide gitignored files
- "git stash apply" not applying untracked files
- How to recover deleted files from git after switching branch without stash
- Git stash clear and drop are not really clearing the changes
- Pull in the oldest stash
- Stash or commit changes so local repo is up to date with remote repo?
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
git stashwill, in fact, make up to three commits. The two that you have observed are the default two: one for the index state—remember that in Git, the index, also called the staging area, contains the next commit to write, and is updated every time yougit addnew contents—and one for the work-tree state. These may differ from each other and/or from theHEADcommit at the time you create the stash.The fundamental issue is that
git stashis not meant only to save your current work-tree, nor only to save your current index state, nor only to save some combination of the two. If you intended to save the current index state, you could simply make an ordinary commit. If you intended to save a combination of the two, you could simply rungit commit -a.Instead,
git stashdefaults to saving both the index state and the work-tree state, separately. This allows you to retrieve both separate states again later, if that's what you mean to do. It allows you to retrieve a mashed-together version of both states, if that's what you mean to do. And, if you use-uor-a, so thatgit stashmakes its third commit containing untracked or untracked-and-ignored files, it allows you recover all those various states.You express your final intent not at the time you save the stash, but rather at the time you recover it.1 This may not be the best possible design, since (a) sometimes it's not possible to recover your intended state, and (b) if you use
git stash popwithout--indexwhen you had intended to use--index, this destroys the separated state and then discards both commits, making it exceedingly difficult to recover. In general, though, deferring decisions is usually a good approach.1If you use
--keep-indexat the time you save the stash, you are in fact asserting at least some intent at save-time. But that's another matter entirely. Moreover, there's a long-standing bug ingit stashthat makes keeping both index and work-tree state separate problematic. See here for details.