0

Im using Tower 2 to manage my bitbucket git repos. Ive added some img files to the repo and editted some html and js files, these are not ready to be committed so i saved them as a stash. This worked fine for the html and js files which were editted filed (as opposed to new files) the img files where new files but its not letting me stash these.

Is there a way to stash new files or do they need be committed first ?

Samuel Herzog
  • 3,561
  • 1
  • 22
  • 21
sam
  • 9,486
  • 36
  • 109
  • 160

2 Answers2

2

This is not a git-tower answer since I don't use that and know nothing of it, but just a general point about git stash.

By default, git stash (whose default action is to do a git stash save) saves the contents of the current index (i.e., the next commit you have been building so far) and the contents of the current work-tree, and does so by making two commits. Because it makes commits, it obeys the usual rules for commits: only files already in the index get committed. This means that in particular, untracked and ignored files are not stashed.

The command-line version of git stash save does, however, have two flags you can supply to modify this behavior. The -u or --include-untracked flag tells it to save untracked files, and the -a or --all flag tells it to save all (untracked and ignored) files. When using these flags, git stash save simply makes a third commit as well, to hold these files.

The tricky thing that git stash save does is to place these two or three commits outside the usual branch system, as a sort of bag on the side. It also cleans up (via git reset --hard and, when using -u or -a, git clean as well) the work-tree after saving your state by making its commits.

These tricks are convenient, but can be confusing. For those new to git it's probably better just to start with ordinary commits, since you should have tools with which to take private (unpublished) commits and modify and combine them (e.g., via interactive rebase and squash).

Community
  • 1
  • 1
torek
  • 448,244
  • 59
  • 642
  • 775
2

TL'DR: Yes.

Actually there are two ways:

Stashing untracked files using Tower 2

From Tower 2 Manual:

Saving Changes on a Stash

Since stashing is such an important feature, Tower makes using it very easy: in the toolbar, you can click [Save Stash] or press [⌘ + ⇧ + S] at any time to save your current local changes.

Providing a short but descriptive message will help you distinguish different Stashes later. As an option, Tower also offers to include untracked files when saving a Stash. (emphasized by myself)

All you need to do is check the little checkbox following the textfield for the stash-message in the Save-Stash-Dialog.

Software hickups

If you did so, but your stash isn't saved correctly, you should probably check in with the Tower Support team. To make their job easier you might want to test stashing via command line first.

Stashing untracked files using the command line client

Regardless of any software you use, you can always stash manually via the command line tool.

The command you are looking for is git stash save -u

Understanding git-stash

As torek's answer explains what is going on with git stash under the hood, I highly suggest you read it and the linked question. In a nutshell Tower does use the command line tools internally and gives you a sophisticated GUI interface for it. As always, you can dive into details and options via the manual on git-stash.

Community
  • 1
  • 1
Samuel Herzog
  • 3,561
  • 1
  • 22
  • 21