git add .
后想撤销怎么操作?git commit -am 'file msg'
添加了错误的 commit 信息想修改怎么操作?git reset --hard HEAD^
删除了最新提交,现在又后悔了,想还原怎么办?.gitignore
中添加规则无效什么原因?git reflog
git commit --amend --no-edit
git rebase -i
git commit --amend
git branch some-new-branch-name
git reset HEAD~ --hard
git checkout some-new-branch-name
git reset HEAD@{number-of-commits-back}
git reset HEAD~ --soft
git stash
git checkout name-of-the-correct-branch
git stash pop
cherry-pick
git checkout name-of-the-correct-branch
git cherry-pick master
git checkout master
git reset HEAD~ --hard
git diff --staged
git diff
View difference between Stage and Working Directorygit diff --staged
View difference between HEAD and Stagegit diff HEAD
View difference between HEAD and Working Directorygit status -v -v
git log
git revert [saved hash]
git checkout [saved hash] -- path/to/file
git fetch origin
git checkout master
git reset --hard origin/master
git clean -d --force
git cherry-pick commitId
即可HEAD
is a reference to the last commit in the currently checked-out branch.git add .
后想撤销怎么操作?
git commit -am 'file msg'
添加了错误的 commit 信息想修改怎么操作?
.gitignore
中添加规则无效什么原因?
https://github.com/geeeeeeeeek/git-recipes/wiki/5.2-代码回滚:Reset、Checkout、Revert-的选择
fatal: Not a git repository (or any of the parent directories): .git
解决办法:你得进入你的工作目录下,然后再git status 或者其它命令就没问题了。
fatal: refusing to merge unrelated histories
说明:这是在 项目A上修改 ./git/config
后,提交到 项目B 上,无法 pull
如果合并了两个不同的开始提交的仓库,在新的 git 会发现这两个仓库可能不是同一个,为了防止开发者上传错误,于是就给下面的提示
fatal: refusing to merge unrelated histories
解决方法 如下
git pull <remote-url> --allow-unrelated-histories
git clone
时加上 --depth=1
,但不一定能解决--depth=1
来解决针对远程已经新建了分支, 在本地如何关联远程的分支
cloudyan@IT0101 /E/git/webtest (master)
$ git fetch origin
// 如果你的命令无效,我在win8中使用1.8.3就上述命令执行无效,
// 可以使用 git checkout -t 本地分支名 远程分支名,如:
// git checkout -t v4 origin/v4 //v3项目中的分支v4,分支名同则可省略,如:git checkout -t origin/gh-pages
// 使用 git branch -r可以查看远程分支
cloudyan@IT0101 /E/git/webtest (master)
$ git checkout dev
Branch dev set up to track remote branch dev from origin.
Switched to a new branch 'dev'
cloudyan@IT0101 /E/git/webtest (testing)
$ git branch --list
* testing
master
git commit --date=2019-07-10T12:00:00
时报错,fatal: could not read ‘/Users/jack/.stCommitMsg’: No such file or directory# 查看 commit.template 以及 Users/xxx,是否配置正确
git config --get commit.template
提示错误
ssh: connect to host ssh.github.com port 443: Network is down
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
可能网络问题
remote: error: GH007: Your push would publish a private email address.
remote: You can make your email public or disable this protection by visiting:
remote: http://github.com/settings/emails
To github.com:dwdjs/xxx.git
! [remote rejected] dev -> dev (push declined due to email privacy restrictions)
error: failed to push some refs to 'git@github.com:dwdjs/xxx.git'
由于设置了邮箱为隐私邮箱,有两种解决方式:
git config --global user.email 'username@users.noreply.github.com'
# 查看所有配置
git config --list
error: RPC failed; curl 92 HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1)
fatal: the remote end hung up unexpectedly
这是因为
HTTP/2
与 Proxy-Connection
响应头头不兼容解决办法
或 改用 ssh 拉取代码(推荐)
参考: