Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git 操作合集 #20

Closed
he-sb opened this issue Apr 16, 2020 · 10 comments
Closed

Git 操作合集 #20

he-sb opened this issue Apr 16, 2020 · 10 comments
Labels
奇技淫巧 吾生也有涯,而折腾无涯

Comments

@he-sb
Copy link
Owner

he-sb commented Apr 16, 2020

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

@he-sb he-sb added the idea label Apr 16, 2020
@he-sb
Copy link
Owner Author

he-sb commented Apr 16, 2020

跳过 Travis-CI :

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

git commit -m "[ci skip] commit message"

@he-sb
Copy link
Owner Author

he-sb commented Apr 16, 2020

@he-sb
Copy link
Owner Author

he-sb commented Apr 16, 2020

使 git status 信息更加现代化:

git status -sb

@he-sb
Copy link
Owner Author

he-sb commented Apr 16, 2020

换行符相关:

编辑器使用 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 he-sb added 奇技淫巧 吾生也有涯,而折腾无涯 and removed idea labels Apr 18, 2020
@he-sb
Copy link
Owner Author

he-sb commented May 17, 2020

取消中文路径转义:

git config --global core.quotePath false

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

git config --global core.ignorecase false

@he-sb
Copy link
Owner Author

he-sb commented Oct 19, 2020

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
Copy link
Owner Author

he-sb commented Oct 19, 2020

@he-sb
Copy link
Owner Author

he-sb commented Nov 13, 2020

@he-sb
Copy link
Owner Author

he-sb commented Dec 7, 2020

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

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

@he-sb
Copy link
Owner Author

he-sb commented Dec 12, 2020

利用 commit 信息关闭 Issues

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

其中 <keyword> 包括:

  • close
  • closes
  • closed
  • fix
  • fixes
  • fixed
  • resolve
  • resolves
  • resolved

一个例子:

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

参考链接:

@he-sb he-sb pinned this issue Dec 14, 2020
@he-sb he-sb changed the title git 操作合集 Git 操作合集 Dec 26, 2020
@he-sb he-sb closed this as completed in a93ed69 Dec 26, 2020
@he-sb he-sb unpinned this issue Dec 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
奇技淫巧 吾生也有涯,而折腾无涯
Projects
None yet
Development

No branches or pull requests

1 participant