Disable git staging area

て烟熏妆下的殇ゞ 提交于 2019-11-29 09:11:31
Jakob Borg

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 staging area.

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.

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.

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.

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!