与Intellij Idea一起使用Git的最佳实践 [英] Best Practices for using Git with Intellij Idea

查看:325
本文介绍了与Intellij Idea一起使用Git的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简而言之:使用Intellij Idea(9)和Git的最佳实践是什么?



上下文



我们最近升级到了idea 9,并开始将Git用于现有项目的新功能。

我们主要使用git命令行来更好地学习该工具。但我们认为我们会选择蜂巢式的头脑来找出git带有想法的最佳实践。



CVS和Git的Idea UI相似,但基本的实现有所不同。



示例问题



例如:
- 与CVS一样,当我们有多个版本的产品时,我们每个人都会拥有1-0,2-0,3-0等分支机构的本地副本,每个分支机构都有自己的Intellij文件(即.ipr,.iws等)。 git方式似乎有一个项目,并使用git分支来切换分支。这很好,但是当您更改分支时,它会为想法带来巨大的开销(因为它必须重新加载每个更改的文件,包括签入的jar)。所以:你还有一个单独的项目(与.git)为每个主要版本或有一个项目,并使用git分支?



- 它是一个好主意使用Autostash?



- 您是否自动将每个修改添加到您的git commit?或者在以后使用git add?

- 您要重新绑定吗?



/ p>

- 任何其他提示/提示/为您工作的内容等等

Final评论



我们仍然在cvs中思考,所以这部分内容已经习惯了git;部分已经习惯了Idea的Ui for git。

这些都是相当基本的问题,因为我们仍然主要使用命令行。另外我听说主意10拥有更好/更强大/更快的git集成工具。

谢谢

解决方案

这是我们在Git / Idea数周后发现的。我已经将此作为社区维基。请投入您的2克朗/厘米/芬尼/美分。



注意:我正在回答我自己的问题,因为我寻求那些易于使用的项目符号。



预设



想法是很棒的工具。这里没有人抱怨。只要观察即可。



最佳实践
$ b


  • <在这一点上(9.0.3)使用Idea的Git比使用Idea的SVN更加难以使用。部分原因是Git(vs SVN)的复杂性,部分原因是Idea的工具并没有在git世界中做所有事情。
  • 因此,您需要使用命令行
  • Idea的合并工具比命令行合并甚至使用mergetool(使用meld或mergetool)更有效。原因是:你在'想法环境'中工作的自由度要高得多,而不是每次都要固定一个皮棉。

  • -alt-y)当你从命令行更新工作树时
  • 观察Git控制台学习idea的git技巧; (版本控制视图,控制台选项卡):


  • $ b

      13:30:58.234:git log -M --follow --name-only --pretty = format:%H%x00%ct%x00 %an%x20%x3C%ae%x3E%x00%cn%x20%x3C%ce%x3E%x00%s%n%n%b%x00 --encoding = UTF-8  -  src / jsp / workspaces / include /edit.jsp 
    13:31:02.437:cd J:\projects\PE-GIT\pe
    13:31:02.437:git annotate -p -l -t -M HEAD - - src / jsp / workspaces / include / edit.jsp




    • 在9.0.3中没有合并上游提交中的冲突的好工具



    示例:




    • Alice确实工作,提交(本地)
      文件A,提交文件B,提交文件
      C

    • Bob工作,提交文件C,提交文件D,提交文件E

    • Alice推送更改

    • Bob将其更改



    来自CVS / SVN,我期望Ideas可以得心应手差异化工具弹出。不,相反,git / idea会抛出一面红旗,我通常最终会使用git mergetool(在linux上是meld od,在windows上是tortoiesmerge)。
    $ b

    注意:也许Idea提供了一个更好的方法。请给我直线。
    请注意:您可以设置.gitconfig以使用Idea的差异化工具吗?



    存储




    • 想法Shelve功能重复Git Stash。两者似乎相似。两者都使用补丁。你可能想要使用其中一个。我还没有弄清楚其中一个或另一个的优势



    大型旧项目




    • 如果您正在研究一个十年前最近迁移到Git的项目,将jar文件签入scm(即先前签入CVS / SVN,其中如果您想签出项目的版本2.0,log4j-1.0.jar位于BRANCH-2-0中,主线包含log4j-9.0.jar),进行小心。想法需要卸载所有的头部罐子,并重新加载罐子 - 检查在2.0。这需要永远。



    其他小东西


    • 即使您已经初始化Git,想法菜单/用户界面仍会显示git init ...。这是令人困惑的,但忽略它。

    • 你不能在Git和CVS / SVN中拥有相同的工作树(尽管用户界面似乎暗示了这一点)。我/我们在最初的让我们尝试git并仍然使用CVS作为备份计划阶段尝试了这一点。它不起作用

    In a nutshell: what are best practcices for using Intellij Idea (9) and Git?

    Context

    We've recently upgraded to idea 9 and have started to use Git for a new feature on existing project.

    We largely use git command line to learn the tool better. But we thought we'd pick the hive-mind to find out what are best practices for git with idea.

    The Idea UI is similar for both CVS and Git, yet the underlying implementations differ a bit.

    Example Questions

    For example: -With CVS, when we had multiple release of a product, each of us would have a local copy of the 1-0, 2-0, 3-0, etc. branches , each with its own Intellij files (i.e. .ipr, .iws, etc.). The "git way" seems to have one project and use 'git branch' to switch branches. This is fine, but it creates huge overhead for idea (as it has to reload each changed file, including checked-in jars) when you change branches. So: do you still have a separate project (with .git) for each "major release" or have one project and use "git branch"?

    -Is it a good idea to use Autostash?

    -Do you automatically add each modification to your git commit? or use "git add" later?

    -Do you rebase?

    -Best way to merge?

    -Any other hints/tips/what-works-for-you,etc.

    Final Comments

    We still "think in cvs" so part of this is getting used to git; part is getting used to Idea's Ui for git.

    These are fairly rudimentary questions as we still use the comand line primarily. Also I've heard idea 10 has better/stronger/faster git integration tools

    Thanks

    解决方案

    Here's what we've found after several weeks of Git/Idea. I've made this a community wiki. Please throw in your 2 kronor/centimos/pfennings/cents.

    Note: I'm answering my own question because I sought those easy-use bullet points.

    Presupposition

    Idea is great tool. No one here is complaining. Just observing.

    Best Practices

    • At this point (9.0.3) Git with Idea is just plain harder to use than SVN with Idea. Part stems from the complexity of Git (vs SVN), partly because Idea's tools don't do everything in the git world.

    • Thus you will need to use the command line

    • Idea's merge tool works much better than command line merging or even using mergetool (using meld or mergetool). The reason: you have much more freedeom to work in the 'idea environment' rather than fixe one lint at a time.

    • Remember to synchronize in Idea (ctrl-alt-y) when you update the working tree from the command line

    • Watching the Git Console to learn idea's git tricks; idea executes git commands there.( Version Control view, Console tab):

    example:

    13:30:58.234: git log -M --follow --name-only --pretty=format:%H%x00%ct%x00%an%x20%x3C%ae%x3E%x00%cn%x20%x3C%ce%x3E%x00%s%n%n%b%x00 --encoding=UTF-8 -- src/jsp/workspaces/include/edit.jsp
    13:31:02.437: cd J:\projects\PE-GIT\pe
    13:31:02.437: git annotate -p -l -t -M HEAD -- src/jsp/workspaces/include/edit.jsp
    

    • Unfortunately Idea does not have good tools for "merging conflicts in upstream commits" in 9.0.3

    Example:

    • Alice does work, commits (locally) file A, commits file B, commits file C
    • Bob does work, commits file C, commits file D, commits file E
    • Alice pushes her changes
    • Bob Pulls his changes

    Coming from CVS/SVN, I expected Ideas handy diffing tool to pop up. No. Instead git/idea throw up a red flag, I usually end up using "git mergetool" (meld od on linux, tortoiesmerge on windows).

    Note: Perhaps Idea provides a better way. Please set me straight. Note to the motivated: can you set up .gitconfig to use Idea's diffing tool?

    Stashing

    • Ideas "Shelve" functionality duplicates "Git Stash". Both seem similar. Both use patches. You probably want to use one or the other. I haven't figured out the advantage of one or the other

    Big Old Projects

    • If you're working on a decade old project recently migrated to Git, with jar files checked into the scm (i.e. previously checked into CVS/SVN, where log4j-1.0.jar is in BRANCH-2-0 and the mainline has log4j-9.0.jar ), PROCEED WITH CAUTION if you want to checkout "version 2.0" of your project. Idea needs to unload all the "head" jars and reload the jars-checked-in-at-2.0. This takes for-ever.

    Other little stuff

    • The idea menus/UI still shows "git init..." even though you've already initialized Git. It's confusing, but ignore it.

    • You cannot have the same working tree in both Git and CVS/SVN (though the UI may seem to imply so). I/we tried this during an initial "let's try git and still use CVS as a backup plan" phase. It didn't work

    这篇关于与Intellij Idea一起使用Git的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆