Skip to content
GitTree
Changes and commits

Stage files, hunks and selected lines

A commit contains only what you stage. In GitTree you stage a whole file, one hunk of it, or just the lines you pick in the diff, and the rest of your edits stay in the working folder for a later commit.

FreeUpdated

Works in GitTree Free: every local Git feature, once you are signed in.

On this page
  1. Before you start
  2. Where to find it
  3. Steps
  4. Expected result
  5. Staging controls
  6. Changes that are staged whole
  7. If something goes wrong
  8. Questions
  9. Related

Before you start

  • A repository is open and has changes: the // WIP row at the top of the graph counts them.
  • Staging only prepares the next commit. It changes nothing in your files and nothing on the remote.

Where to find it

  • The Working Changes panel: select the // WIP row at the top of the graph, or View Changes in the blue bar above the commit details.
  • The diff of a file: select the file in Unstaged Files or Staged Files; it opens in the middle with its hunk and line controls.
  • Hover a file row for Stage File, Unstage File and Discard Changes to File….
ActionmacOSWindows and Linux
Stage the selected files (in the file list)SS
Unstage the selected files (in the file list)UU
Next change in the diffF7F7
Previous change in the diff⇧F7Shift+F7
Commit⌘EnterCtrl+Enter

Steps

  1. Open the working changes

    Select the // WIP row at the top of the graph. The Working Changes panel lists Unstaged Files and Staged Files, each with a count, and the commit form below them.

    The Working Changes panel: four unstaged files, one staged file and the commit form
    1 is the // WIP row; 2 the files you changed but have not staged; 3 the files already staged for the next commit.GitTree interface with a demonstration repository.
  2. Stage whole files

    Hover a file and choose Stage File, or select one or more files and press S. Stage All Changes stages every file at once. Staged files move to Staged Files; Unstage File (or U) moves one back.

  3. Stage one hunk, or only the lines you pick

    Select a file to open its diff. Each block of changes (a hunk) has Stage Hunk. To stage less, tick the boxes beside the changed lines you want (Shift+click picks a range), then choose Stage Lines in the bar that shows how many lines are picked.

    Animation: the WIP row opens the changes, a file’s diff opens, two changed lines are ticked and Stage Lines is chosen
    Two lines of InviteDialog.tsx are picked and staged; the rest of the file stays unstaged.GitTree interface with a demonstration repository.
  4. Check what will be committed

    Select the file under Staged Files: its diff now shows only what you staged, with Unstage Hunk and Unstage Lines to take part of it back. The commit button names how many files it will commit.

Expected result

The file can appear in both lists: the lines you staged under Staged Files, the rest under Unstaged Files. Your file on disk still holds every edit.

When you commit, only the staged part goes into the commit. To continue, write and create the commit.

Staging controls

Where each staging action is
ControlWhereWhat it does
Stage All ChangesAbove Unstaged FilesStages every changed file, new files included.
Stage File / Unstage FileOn a file row (hover), or S and U in the listMoves the whole file between the lists.
Stage Hunk / Unstage HunkAbove each hunk of the diffStages or unstages that block of lines.
Stage Lines / Unstage LinesIn the bar that appears when lines are pickedStages or unstages only the picked lines. Clear drops the selection.
Stage Changes to CommitThe commit button, while nothing is stagedStages every change first, then lets you commit.

Changes that are staged whole

Some changes have no lines to pick, so GitTree offers only the file-level action: binary files, renames and copies, Git LFS pointers, submodule changes, and a file mode change (staged together with the content).

If you hide whitespace in the diff and the file has whitespace-only changes, lines cannot be picked: choose Show Whitespace first, or stage the whole file.

If something goes wrong

The commit button says Stage Changes to Commit

Nothing is staged yet. Stage the files, hunks or lines you want, or choose the button to stage everything before committing.

“The diff changed since it was shown”

The file changed on disk (an editor saved it) after the diff appeared, so GitTree refused to stage a selection that no longer matches. Look at the refreshed diff and pick the lines again.

I discarded lines by mistake

Discard Lines and Discard Hunk save a recovery snapshot first. Choose Undo in the toolbar (Ctrl+Z, ⌘Z on a Mac) to bring them back (Undo and Redo).

Questions

Is this the same as git add -p?

It does the same job: it puts part of a file into the index. Instead of answering prompts hunk by hunk, you see the whole diff and tick the lines you want.

Do the picked lines need to be next to each other?

No. Tick any changed lines in the file, in one hunk or several, and stage them together.