![]() ![]() However, the answer to the question as asked-specifically How to force git to use fast-forward when applying a stash-is that you can't, and in fact, the question doesn't even make sense: fast-forward is a different concept from stashing and unstashing. I linked in a comment to How do I properly git stash/pop in pre-commit hooks to get a clean working tree for tests? which shows how to do the final pop (or equivalent), and some of the caveats around this. All the usual caveats around hard resets apply. You need to git reset -hard HEAD (or anything equivalent) before applying with -index like this. Or, I need to 'rebase' the stash so that it's only parent is the index. The script does not mutate the files in anyway, so really I'm just looking to 'fast-forward' the stash apply. Git then tries to perform a three-way merge.īut in my use case, this doesn't make sense. I have some idea that this behaviour might be due to the stashed changes having two parents-the first being the HEAD, and the second being the index. How do I get git to apply the changes in the stash preferentially over the staged changes? $ sed -i 's/a/b/g' main.py # now it's print('b')ĬONFLICT (content): Merge conflict in main.py For example, $ echo "print('a')" > main.py # main.py already exists However, git stash pop will always create a merge conflict if there are both staged and unstaged changes on the same line. and then git stash pop to reapply them after the scripts.To achieve this, I use git stash push -keep-index to remove unstaged changes.But the script should only act on staged changes.I'm writing a pre-commit/pre-push script.Hopefully this answer is helpful to someone, putting everything together all in one answer. zshrc or equivalent to make exist long-term. unstashall apply or unstashall pop of course you'd put in your. Note: In this form, you need to supply an action argument as well as the identifier if you're going to supply a stash identifier, e.g. Perhaps this (instead of the second alias, above) : function unstashall() Note that the latter might be better as a shell script or function, to allow parameters to be supplied to git stash, in case you don't want pop but apply, and/or want to be able to specify a specific stash, rather than just taking the top one. gftu` git stash'Īlias unstashall='git stash pop git rm -cached `cat. which could also be easily scripted - even aliases would do (presented in zsh syntax adjust as needed) : alias stashall='git ls-files -o >. Git add `cat files-to-untrack` # note: files-to-untrack will be listed, itself! Git stash pop # or apply instead of pop, to keep the stash availableĪnd then you can continue working, in the same state as you were in before the git add (namely with an untracked file called path/to/untracked-file plus any other changes you might have had to tracked files).Īnother possibility for a workflow on this would be something like: git ls-files -o > files-to-untrack # On master: don't forget to un-add path/to/untracked-file Git stash save "don't forget to un-add path/to/untracked-file" # stash w/reminder So, what can you do? Well, you have to truly add the file, however, you can effectively un-add it later, with git rm -cached: git add path/to/untracked-file This will fail, as follows: path/to/untracked-file: not added yetįatal: git-write-tree: error building trees And the following will NOT work: git add -N path/to/untracked/file # note: -N is short for -intent-to-add However, the question is also raised in another answer: What if you don't really want to add the file? Well, as far as I can tell, you have to. This gave back to me my ability to work on the same project in eclipse.Īs has been said elsewhere, the answer is to git add the file. This pasted the same files back in my workspace. Once this was done successfully, I used git stash pop I proceeded on with completing the procedure for pushing the committed files to remote. Absence of these files takes away my capability of working on my work location in eclipse. project file, I used git stash -include-untrackedĪnd it removed the files from my workspace. classpath are not stashed.įor stashing the modified. gitIgnore fiels and the untracked files viz.project and. However, final push cannot be performed unless the modified. I first of all selectively added my rest of the files and committed for staging. project files are important for eclipse - which is my java editor. I had to perform a modification to my gitIgnore file to avoid movement of. This will place the file back in your local workspace. And you can revert git stash by using following commands git stash pop Git stash removes any untracked or uncommited files from your workspace. In git bash, stashing of untracked files is achieved by using the command git stash -include-untracked ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |