“IDEA:Git相关”的版本间差异
		
		
		
		
		
		跳到导航
		跳到搜索
		
				
		
		
	
| 第66行: | 第66行: | ||
  2、Stash 将保存所有 uncommitted changes;  |   2、Stash 将保存所有 uncommitted changes;  | ||
     Shelve 可以选择保存部分 uncommitted changes。  |      Shelve 可以选择保存部分 uncommitted changes。  | ||
== 关于:Undo、Revert、Drop、Reset commit ==  | |||
 参见:参见:<big>'''[https://www.jetbrains.com/help/idea/undo-changes.html IDEA_Doc:undo-changes.html]'''</big>  | |||
操作对照:  | |||
: [[File:IDEA:Git:Option of commit.png|400px]]  | |||
=== 撤销(Undo) ===  | |||
 撤销提交(“Undo the last commit”),不能对“受保护分支”(protected branch)操作。  | |||
 关于“受保护分支”:  | |||
     ——本地“受保护分支”,可在 IDEA 中设置;  | |||
     ——如果远程分支为“受保护分支”,则本地迁出时也为“受保护分支”;  | |||
== 关于:“强制推送” ==  | == 关于:“强制推送” ==  | ||
2022年5月27日 (五) 22:28的版本
关于:merge、rebase、cherry-pick、应用独立更改、应用独立文件
参见:IDEA_Doc:apply-changes-from-one-branch-to-another
- merge:
 - rebase:
 - cherry-pick 
:将某个 commit 应用到当前分支,会在 HEAD 新增一个 commit。
- 中文插件翻译为“优选”。
 
 - Apply separate changes(应用独立更改):将某个 commit 的 changes 应用到当前分支,会反应在 ChangeList 中。
 - Apply separate files(应用独立文件,
):将某个 commit 的 files 应用到当前分支,会反应在 ChangeList 中。
 
关于:Resolve conflicts(冲突解决)
参见:IDEA_Doc:resolve-conflicts
- “Non-Conflicting Changes”:仅在左侧(或右侧)新增、修改、删除的冲突内容;
 - “Conflicting Changes”:同时在左右两侧修改过的冲突内容;
- 手动确定决解方案。
 
 
说明:
- 图标:
×:忽略左/右侧;>>:应用左/右侧,到当前冲突;
 - 右键:
接受左侧:接受左侧,用于当前冲突(但不忽略右侧);接受右侧:…类上…使用左侧 解决:接受左侧,用于当前冲突,并忽略右侧;使用右侧 解决:…类上…自动解决:综合左右,应用于当前冲突;忽略:忽略当前冲突;(保持原样)
 - 按钮:
接受左侧:接受左侧,用于所有冲突,并完成冲突解决;接受右侧:…类上…
 
关于:行末标识冲突
行末标识符:LF(Unix, Linux and MacOS),CRLF(Windows)
解决:
- 全局设置(通过命令):
# on Windows git config --global core.autocrlf true # on Linux and macOS git config --global core.autocrlf input
 - 仓库设置(通过配置文件“.gitattributes”):
 
关于:Shelve、Stash
参见:IDEA_Doc:work-on-several-features-simultaneously Stash(保存工作现场)与 Shelve(搁置): 1、Stash 由 git 生成,可在 IDEA 内外使用; Shelve 由 IDEA 生成,在 IDEA 内使用。 2、Stash 将保存所有 uncommitted changes; Shelve 可以选择保存部分 uncommitted changes。
关于:Undo、Revert、Drop、Reset commit
参见:参见:IDEA_Doc:undo-changes.html
操作对照:
撤销(Undo)
撤销提交(“Undo the last commit”),不能对“受保护分支”(protected branch)操作。
关于“受保护分支”:
    ——本地“受保护分支”,可在 IDEA 中设置;
    ——如果远程分支为“受保护分支”,则本地迁出时也为“受保护分支”;
关于:“强制推送”
Git 的“强制推送”(git push --force-with-lease):强制推送本地分支到远程,将会忽略远程分支版本比本地高【即,抛弃比当前 commit 更高版本的 commit】;
【慎用!!!】
示例:
不能使用“强制推送”?
IDEA 不能对“受保护分支”(Git 相关设置中)进行强制推送。
“受保护分支”设置:
- 如上,删除或更改此处设置,则可以对 master 分支进行强制推送了。
 
FAQ
推送错误:“git@github.com: Permission denied (publickey).”
使用 IDEA 推送本地仓库到 GitHub 时,遇到错误:“git@github.com: Permission denied (publickey).”
错误信息:
- IDEA git:
 - ssh 测试:
- ssh -T git@github.com:用于测试 SSH 到 GitHub 是否可用;
 - ssh -vT git@github.com:用于测试 SSH 到 GitHub 是否可用,并会显示详细信息;
 
 
原因:推送到 GitHub 需要 SSH,当前未配置相关内容。
解决:
- 本地:
- 生成 SSH 密钥对:
- 由于本地已存储了其他密钥对(“id_rsa、id_rsa.pub”),所以此处修改了存储文件名;
 
 - 新建 config 文件:
- 由于修改了密钥文件的名称(或位置),所以需要 config 文件(C:\Users\eijux\.ssh\)进行配置;
 
# github Host github.com HostName github.com PreferredAuthentications publickey IdentityFile C:\\Users\\eijux\\.ssh\\id_rse_github
 
 - 生成 SSH 密钥对:
 - Github:配置 SSH keys。
 - SSH 测试: