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 操作 #71

Open
yubaoquan opened this issue Jul 17, 2019 · 7 comments
Open

常用 git 操作 #71

yubaoquan opened this issue Jul 17, 2019 · 7 comments

Comments

@yubaoquan
Copy link
Owner

yubaoquan commented Jul 17, 2019

删除文件/文件夹, 保留在本地文件系统

git rm --cached mylogfile.log
git rm --cached -r mydirectory

设置用户信息

git config user.name xxx
git config user.email xxx

修改上个commit的用户信息

git commit --amend --author="Author Name <[email protected]>"

查看当前 commit

git rev-parse HEAD

branch

添加远程分支

git remote add origin <url>

设置远程分支

git remote set-url origin <url>

更新远程分支

git remote prune origin

删分支

git branch -d [branchName]

改分支名

git branch -m new-name
git push origin :old-name new-name
git push origin -u new-name

同步远程分支

git fetch -p

tag

添加/推送tag

git tag -a [tag name] -m [message]
git push --follow-tags

查看 tag 列表

git tag -l
@yubaoquan
Copy link
Owner Author

Command line instructions

Git global setup
git config --global user.name "aaa"
git config --global user.email "[email protected]"

Create a new repository

git clone xxx
cd test
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

Existing folder

cd existing_folder
git init
git remote add origin xxxxx
git add .
git commit
git push -u origin master

Existing Git repository

cd existing_repo
git remote add origin xxxxx
git push -u origin --all
git push -u origin --tags

@yubaoquan
Copy link
Owner Author

yubaoquan commented Feb 19, 2020

git pull origin xxxbranch --allow-unrelated-histories

commit with husky disabled

git commit --no-verify

@yubaoquan yubaoquan pinned this issue Feb 23, 2021
@yubaoquan
Copy link
Owner Author

查看/取消代理

git config --global http.proxy

git config --global --unset http.proxy

@yubaoquan
Copy link
Owner Author

yubaoquan commented Jun 8, 2021

处理 fatal: the remote end hung up unexpectedly

方法一:

修改提交缓存大小为500M,或者更大的数字

git config --global http.postBuffer 524288000

# some comments below report having to double the value:

git config --global http.postBuffer 1048576000

或者在克隆/创建版本库生成的 .git目录下面修改生成的config文件增加如下:

[http]  
  postBuffer = 524288000

然后重新推送。

方法二:

配置git的最低速度和最低速度时间:

git config --global http.lowSpeedLimit 0
git config --global http.lowSpeedTime 999999 

--global配置对当前用户生效,如果需要对所有用户生效,则用--system

参考资料

@yubaoquan
Copy link
Owner Author

根据 token 设置 remote

git remote set-url origin https://<personal_token>@github.com/yubaoquan/hw-6-1.git

@yubaoquan
Copy link
Owner Author

设置默认主分支

git config --global init.defaultBranch xxx

初始化并设置分支名

git init --initial-branch=xxx
git init -b xxx

@yubaoquan
Copy link
Owner Author

windows 配置 SSH key

要配置 gitlab 的 ssh key 用于代码提交,你可以参考以下步骤:

打开本地 git bash,使用如下命令生成 ssh 公钥和私钥对:

ssh-keygen -t rsa -C '[email protected]'

其中 -C 参数是你的邮箱地址,如果你不想设置密码,可以直接回车。

打开 ~/.ssh/id_rsa.pub 文件,复制其中的内容。~ 表示用户目录,比如我的 windows 就是 C:\Users\Administrator。

打开 gitlab,找到 Profile Settings --> SSH Keys --> Add SSH Key,并把上一步中复制的内容粘贴到 Key 所对应的文本框,在 Title 对应的文本框中给这个 ssh key 设置一个名字,点击 Add key 按钮。

测试是否成功,在命令行中输入:

如果显示 welcome,则表示安装成功。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant