Skip to content

Instantly share code, notes, and snippets.

@dcchambers
Last active March 15, 2022 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcchambers/fc86a689f45ff0bbe1a0a8793498d406 to your computer and use it in GitHub Desktop.
Save dcchambers/fc86a689f45ff0bbe1a0a8793498d406 to your computer and use it in GitHub Desktop.
Stage parts of a file for git commit

Using Git Interactive Staging (git add -i)

  • If you have made multiple changes to a file but only want to stage/commit part of that file to git, you can use git's interactive staging tool.
  1. git add -i
  2. Select 5 or p for patch
  3. Select the file(s) with the changes you want to interactively stage.
  4. Git will walk you through different chunks of code in the files you have selected, and you can pick if you want to stage that chunk of code.
  5. Once done, commit your code as normal.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment