he-sb / tech

My blog related to technique.
MIT License
9 stars 2 forks source link

Git 操作合集 #20

Closed he-sb closed 3 years ago

he-sb commented 4 years ago

用于记录 Git 相关操作,以防便自己忘记时查阅……

he-sb commented 4 years ago

跳过 Travis-CI :

commit 信息中加入 [ci skip] ,例如:

git commit -m "[ci skip] commit message"
he-sb commented 4 years ago

推送提交到远程仓库 - GitHub 帮助

he-sb commented 4 years ago

使 git status 信息更加现代化:

git status -sb
he-sb commented 4 years ago

换行符相关:

编辑器使用 LF 换行符,然后配置 Git :

git config --global core.safecrlf true
git config --global core.autocrlf false

参考链接:

Easy-Hexo/CONTRIBUTING.md - 配置-git

GitHub 第一坑:换行符自动转换 · Issue #22 · cssmagic/blog

he-sb commented 4 years ago

取消中文路径转义:

git config --global core.quotePath false

设置大小写敏感,保持 Mac/Win/Linux一致性;在目录名大小写修改时,commit 可正常提交:

git config --global core.ignorecase false
he-sb commented 3 years ago

Git 添加远程仓库

git remote add <remote_name> <url>

向远程仓库提交:

# 第一次提交时需添加 -u 参数关联本地与远程分支
# 提交到远程的同名分支
git push <remote_name> <branch_name>
# 提交到远程的指定分支
git push <remote_name> <local_branch>:<remote_branch>
# 本地与远程同名分支建立关联后可以直接使用以下命令,其中 <remote_name> 也可以省略
git push <remote_name>

从远程仓库拉取更新:

# 指定远程仓库与分支
git pull <remote_name> <remote_branch>:<local_branch>
# 不指定,使用默认远程仓库与分支
git pull

参考链接:

git操作之pull拉取远程指定分支以及push推送到远程指定分支


查看当前当前仓库已添加的远程仓库:

git remote
he-sb commented 3 years ago

删除本地与远程分支

git 删除本地分支与远程分支_bitcarmanlee的博客-CSDN博客

he-sb commented 3 years ago

git 保存账号密码 - sdfwew - OSCHINA - 中文开源技术交流社区

he-sb commented 3 years ago

如果本次操作只有对文件的【修改】,而没有【新增】或【删除】文件,可以直接用 git commit -am "<commit messages>" 来提交修改,省略掉 git add 操作。

-a 选项跳过了暂存区,直接提交了所有修改过的已跟踪的文件。

he-sb commented 3 years ago

利用 commit 信息关闭 Issues

在提交改动到【默认分支】时,通过在 commit message 中加入 <keyword> #<issues number> 来使本次 commit 关闭相应的 Issues,并在对应 Issues 中关联引用本次提交。

其中 <keyword> 包括:

一个例子:

git commit -m "Commit message example. Close #666"

参考链接: