虽然天天在使用Git, 以前也看过相关资料, 但总是在遗忘, 写这个就当作是回忆
Mac下直接用命令行, Window下用 Gitbash操作体验其实差不多
- 全局配置
git config --global user.name "lys"
git config --global user.email lysi@163.com
对应的 ~/.gitconfig 文件是长这个样子的
[user]
name = liuyangsheng
email = lysi@163.com
检查配置:
git config --list
- clone
# clone远程仓库, 自定义本地仓库名字
git clone http://xxx/xx.git myname
- 从暂存区撤回
echo 'hello' > README (新文件)
git add demo (此时加入暂存区)
git status
----------------------------
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: README
----------------------------
git rm --cached README (此时从暂存区撤回)
如果是修改一个已被跟踪的文件
git reset HEAD <file>...
git checkout <file> (撤回本地修改)
神器, 上次提交后有修改, 当作一个提交
git commit --amend
本地代码推到远端新建项目
git remote add pb https://github.com/paulboone/ticgit
git push [remote-name] [branch-name]
git tag -a v1.4 -m 'my version 1.4'
git show v1.4
后期打标签
git tag -a v1.2 9fceb02
默认情况下, git push 命令并不会传送标签到远程仓库服务器上
git push origin [tagname]
推送所有标签
git push origin --tags
在 Git 中你并不能真的检出一个标签,因为它们并不能像分支一样来回移动。 如果你想要工
作目录与仓库中特定的标签版本完全一样,可以使用 git checkout -b [branchname]
[tagname] 在特定的标签上创建一个新分支:
$ git checkout -b version2 v2.0.0
Switched to a new branch 'version2'
# 设置别名
git config --global alias.unstage 'reset HEAD --'
# 建新分支并切换
git checkout -b iss53
# 是以下两条命令的缩写
$ git branch iss53
$ git checkout iss53
如果不想在每一次推送时都输入用户名与密码,你可以设置一个 `credential
cache''。 最简单的方式就是将其保存在内存中几分钟,可以简单地运行
`git config --global credential.helper cache 来设置它
git checkout -b serverfix origin/serverfix
这会给你一个用于工作的本地分支,并且起点位于 origin/serverfix