Disable git staging area

好久不见. 提交于 2019-12-18 05:34:10

问题


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, https://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)


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


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.




回答5:


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.



来源:https://stackoverflow.com/questions/3834627/disable-git-staging-area

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