KRB
KRB

Reputation: 5175

Using Git, if I have 20 changes and I add - commit - push 5 of them. Will the other 15 still be there?

I want to make sure my changes are safe when I add "some" of my changes and commit - push them to the branch. I am working on separate tasks and don't want to add - commit - push yet for some.

Thanks!

Upvotes: 0

Views: 91

Answers (2)

Useless
Useless

Reputation: 67743

Adding, committing and pushing don't alter your working tree at all; they're perfectly safe.

If you're working on seperate tasks and don't want un-staged/un-committed changes getting mixed together (or you want to keep un-committed changes for several branches), you can also use git stash to keep your working tree changes organised.

Upvotes: 0

Mark Longair
Mark Longair

Reputation: 467341

Yes, git is an excellent system for this workflow because of the "staging area" or "index". So long as you don't add -a to git commit, only the files that you have added with git add will have their version updated in the next commit. (When you git commit, the tree that's recorded in the commit is the state of the index.)

In fact, you can do finer than per-file granularity - I frequently only stage some changes from a particular file by using:

git add -p whatever.c

... and just selecting particular changes. (If the changes it offers you aren't fine enough, you can press s to split the change down. If that's still too much, you can use e to edit precisely the change that will be staged.)

As you're staging things, it's helpful to frequently do:

  • git diff

and:

  • git diff --cached

Broadly speaking, git diff shows you the changes that haven't been staged yet, while git diff --cached shows you the changes that have been staged.

Upvotes: 2

Related Questions