简体   繁体   English

禁用git暂存区域

[英]Disable git staging area

I really don't like the git staging area, it just makes my life unnecessarily confusing. 我真的不喜欢git临时区域,它只是让我的生活不必要地混乱。

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). 所以git diff显示了存储库和我的工作目录之间的差异(我不必也输入git diff --cached),所以git ci会检查我的整个工作副本(而不仅仅是已经上传的部分)。

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. 我没有选择更换为不同的DVCS,我不想学习喜欢临时区域。 Please do not post to suggest these :( 请不要发布建议这些:(

Thanks, -Shawn 谢谢,-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) PS:我在superuser.com上问了这个问题, https://superuser.com/questions/192022/disable-git-staging-area ,但该论坛似乎发布的内容少得多(只有118个标记的git,而这里只有4448个)

No. You learn to love it. 不,你学会喜欢它。

On a more serious note, git add -A; git commit 更严重的是, git add -A; git commit git add -A; git commit is probably your friend. git add -A; git commit可能是你的朋友。 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 . git add -A比通常的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 例如,您可以创建一个diff命令,以最小的输入执行您想要的操作:在.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. 然后你可以简单地做git di并获得你自己的diff或git co并获得你自己的个人提交命令。

You could just use git commit -a to commit all changed/deleted files. 您可以使用git commit -a提交所有已更改/删除的文件。 You would still have to add untracked files manually thought. 您仍然需要手动添加未跟踪的文件。

I came from Subversion and was confused by the staging area at first too. 我来自Subversion并且最初也被临时区域弄糊涂了。 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. 暂存区域是(IMO)Git最大的优势之一,并且真正展示了它与其他任何DVCS的不同之处。

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 练习git add . && git commit git add . && git commit . git add . && git commit

If you don't like it use another VCS. 如果你不喜欢它,请使用另一个VCS。 Forced to use a git repository? 强制使用git存储库? See some of the available plugins that are compatible, such as hg-git . 查看一些兼容的可用插件,例如hg-git


Personally I would learn to play to git's strengths instead of fighting it. 就个人而言,我会学会发挥git的优势,而不是与之斗争。 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. Boom, git add [files]然后提交并推送。 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. 即使有90%的时间你会忽略它,它确实很有用。

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. 我知道这不是你想要听到的,但实际上,当你停止对抗工具并​​学会忍受它的那一刻就是它停止使用该工具“痛苦”的那一刻。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM