IDEA:Git相关

来自Wikioe
跳到导航 跳到搜索


关于:merge、rebase、cherry-pick、应用独立更改、应用独立文件

参见:IDEA_DOC:apply-changes-from-one-branch-to-another
  1. merge:
  2. rebase:
  3. cherry-pick IDEA:icons:cherryPick.svg:将某个 commit 应用到当前分支,会在 HEAD 新增一个 commit。
    • 中文插件翻译为“优选”。
  4. Apply separate changes(应用独立更改):将某个 commit 的 changes 应用到当前分支,会反应在 ChangeList 中。
    IDEA:Git:Apply separate changes.png
  5. Apply separate files(应用独立文件,IDEA:icons:get.svg):将某个 commit 的 files 应用到当前分支,会反应在 ChangeList 中。
    IDEA:Git:Apply separate files.png

关于:Resolve conflicts(冲突解决)

参见:IDEA_DOC:resolve-conflicts

注:

  1. “Non-Conflicting Changes”:仅在左侧(或右侧)新增、修改、删除的冲突内容;
    • 可以通过:IDEA:icons:Apply All Non-Conflicting Changes.svgIDEA:icons:Apply Non-Conflicting Changes from the Left Side.svgIDEA:icons:Apply Non-Conflicting Changes from the Right Side.svg 来快速解决。
  2. “Conflicting Changes”:同时在左右两侧修改过的冲突内容;
    • 手动确定决解方案。

关于:行末标识冲突

行末标识符:LF(Unix, Linux and MacOS),CRLF(Windows)

解决:

  1. 全局设置(通过命令):
    # on Windows
    git config --global core.autocrlf true
    
    # on Linux and macOS
    git config --global core.autocrlf input
    
  2. 仓库设置(通过配置文件“.gitattributes”):
  3. 参见:Github_DOC:configuring-git-to-handle-line-endings

关于:Shelve、Stash

参见:IDEA_DOC:work-on-several-features-simultaneously

关于:“强制推送”

Git 的“强制推送”(git push --force-with-lease):强制推送本地分支到远程,将会忽略远程分支版本比本地高【即,抛弃比当前 commit 更高版本的 commit】;

【慎用!!!】

示例:

  1. 强制推送前:
    IDEA:Git:强制推送前.png
  2. 强制推送:
    IDEA:Git:强制推送.png
  3. 强制推送后:
    IDEA:Git:强制推送后.png

不能使用“强制推送”?

IDEA 不能对“受保护分支”(Git 相关设置中)进行强制推送。

“受保护分支”设置:

IDEA:Git:强制推送设置:“受保护分支”.png
  • 如上,删除或更改此处设置,则可以对 master 分支进行强制推送了。

FAQ

推送错误:“git@github.com: Permission denied (publickey).”

使用 IDEA 推送本地仓库到 GitHub 时,遇到错误:“git@github.com: Permission denied (publickey).”

错误信息:

  • IDEA git:
    IDEA:推送失败“git@github.com Permission denied (publickey)”.png
  • ssh 测试:
    SSH:测试连接git@github.com:失败.png
    • ssh -T git@github.com:用于测试 SSH 到 GitHub 是否可用;
    • ssh -vT git@github.com:用于测试 SSH 到 GitHub 是否可用,并会显示详细信息;
原因:推送到 GitHub 需要 SSH,当前未配置相关内容。

解决:

  1. 本地:
    1. 生成 SSH 密钥对:
      • 由于本地已存储了其他密钥对(“id_rsa、id_rsa.pub”),所以此处修改了存储文件名;
      C:\Users\eijux>ssh-keygen -t rsa -C "chen@eijux.com"
      Generating public/private rsa key pair.
      Enter file in which to save the key (C:\Users\eijux/.ssh/id_rsa): C:\Users\eijux/.ssh/id_rse_github
      ...
      
      SSH:生成github密钥对.png
      得到密钥对文件:“id_rse_github、id_rse_github.pub”;
    2. 新建 config 文件:
      • 由于修改了密钥文件的名称(或位置),所以需要 config 文件(C:\Users\eijux\.ssh\)进行配置;
      # github
      Host github.com
      HostName github.com
      PreferredAuthentications publickey
      IdentityFile C:\\Users\\eijux\\.ssh\\id_rse_github
      
  2. Github:配置 SSH keys
    1. 步骤:Setting -> SSH and GPG keys:“New SSH key”;
    2. 将本地生成的公钥“id_rse_github.pub”内容复制到 GitHub 的“New SSH key”;
      Github:添加 SSH key.png
  3. SSH 测试:
    ssh -T git@github.com
    # 或
    ssh -vT git@github.com
    
    SSH:测试连接git@github.com:成功.png