views:

91

answers:

5

I really don't like the git staging area, it just makes my life unnecessarily confusing.

Is it possible to disable it so that all edited and new files are in a single context? So that git diff shows the diff between the repository and my working directory (and I don't have to also type git diff --cached) and so that git ci checks in my whole working copy (not just the part that's staged).

If not, alternatives (like setting up cofigurations) so that it appears that I don't have a staging are would be great too.

I do not have the option of changing to a different DVCS and I don't want to learn to like the staging area. Please do not post to suggest these :(

Thanks, -Shawn

PS: I asked this on superuser.com, http://superuser.com/questions/192022/disable-git-staging-area, but that forum seems to have much less posted (only 118 tagged git compared to 4448 here)

A: 

You could just use git commit -a to commit all changed/deleted files. You would still have to add untracked files manually thought.

I came from Subversion and was confused by the staging area at first too. But you will find it to be very useful. If you stage changes you've tested but make more changes that break your build, you can reset back to your staged changes.

sirlancelot
Yep, I always use git ci -a these days, but (unfortunately) I cannot set ci = commit -a in my rc because then I couldnt' commit only one file (via git ci foo) because it complains about clash between -a and explicit file list.
sligocki
+3  A: 

The staging area is (IMO) one of Git's greatest strengths and really shows how it's different from just about any other DVCS out there.

You can use

git commit -a

to automatically add changed files. For untracked files you are on your own though. Practice git add . && git commit.

If you don't like it use another VCS. Forced to use a git repository? See some of the available plugins that are compatible, such as hg-git.


Personally I would learn to play to git's strengths instead of fighting it. Imagine you are in the middle of a big messy branch, but you need to commit a few selective changes for production. Boom, git add [files] and then commit and push. Go back to work without messing anything else up. There are countless other examples, but that's perhaps the easiest to understand.

Josh K
Not an option to use another. I'm stuck with this tool.
sligocki
@sligocki: You can use several options instead of git to emulate a git repository. See [hg-git](http://hg-git.github.com/).
Josh K
no, I can't. I'm really tired of people saying this! I am using tools that are built on top of git, I do not have an option to use another DVCS or these tools will not work and the entire advantage of using a DVCS in the first place would be gone.
sligocki
@sligocki: Don't use tools, use the CLI. Really it isn't that complicated.
Josh K
@Josh K: How hard is this to understand! I work in a company that has a central perforce repository. Most people here use p4, but I think that p4 is antiquated and disasterous, we have a tool built on top of git as an alternative that allows all the beauty and wonder of DVCS. My choice is to: A) use p4, B) use the tool built on git and thus us git or C) roll my own. I do not want to use p4 or roll my own. So yes, it is rather complicated even though you think it couldn't possibly be!
sligocki
@sligocki: Considering you don't mention *any* of that in your initial question I would say pretty darn hard.
Josh K
@Josh K: Right, I didn't mention any of this because it isn't relevant. I just want to know how to disable the staging area. This question does not require you to know all the details of why. But you make it seem like I'm an idiot and should just use X and Y. You are not answering my question and not helping me because you think you know better than me.
sligocki
@sligocki: Those details are relevant to the question.
Josh K
+3  A: 

No. You learn to love it.

On a more serious note, git add -A; git commit is probably your friend. That way, you avoid most of the interactions with (and benefits of) the index.

git add -A is more powerful than the usual git commit -a. It will find new files as well as staging modified content and removing files that are no longer in the working tree.

calmh
+2  A: 

Aliases are your friends.

For instance, you can create a diff command that does what you want with minimal typing: in your .gitconfig put

[alias]
        di = diff HEAD
        co = commit -a

You can then simply do git di and you get your own diff, or git co and get your own personal commit command.

EOL
but then git di will not show me what is in my working dir, I want git diff to show me the change that will be committed when I do commit -a.
sligocki
Also, I cannot set co = commit -a in my rc because then I couldn't commit only one file (via git ci foo) because it complains about clash between -a and explicit file list.
sligocki
@sligocki: I changed the alias so that `git di` gives you what you indicated in your first comment. As for your 2nd comment: you can commit a single file with the usual `git commit foo`.
EOL
@EOL: Ah, great, thanks for the diff HEAD suggestion, that looks helpful. As for the second comment, I would rather have one command for both. If not, I will probably continue to type git commit -a (it's become second-nature at this point anyway).
sligocki
+2  A: 

and I don't want to learn to like the staging area. Please do not post to suggest these :(

Like all the others. I'm going to suggest you learn to like the staging area. It really is useful even though 90% of the time you'll be ignoring it.

If you currently don't find it useful then I think you're thinking about commits wrong. You're still thinking in terms of single files or everything at once. The correct way to think about commits is per feature/fix and features/fixes are often spread accross more than one file. You should group related changes into a single commit. And sometimes that group of changes does not encompass all the current changes. Which is when the staging becomes useful.

I know this is not what you want to hear but really, the moment you stop fighting the tool and learn to live with it is the moment it stops being "painful" to use the tool.

slebetman
Thanks slebetman, I do see why the staging area could be useful. It is not actually painful for me right now, just makes things more complicated, every once and a while I'll run git diff and be confused why some of the files aren't there. In my situation, I'm actually pushing from git into a perforce repo, so the git revisions are only for me and so can be much more crude. So I do not find myself wanting to craft the revision history, just use it to revert to a previously working state or try new development paths.
sligocki
Rather than doing that, try instead making your changes, and then use git diff only to see "Ok, what have I yet to add to the current commit". If you see that the difference is what you want to add, then add it. If not, then delete or ignore it. Keep working until git diff shows no changes, then you will be ready to commit your changes.
Arafangion