Workspace:工作区 Index / Stage:暂存区 Repository:仓库区(或本地仓库) Remote:远程仓库
初始化一个仓库:git init
添加文件:git add 文件名
添加所有文件:git add *
提交到本地仓库: git commit -m "提交说明"
查看仓库的状态:git status
查看发生更改的文件的具体改变位置:git diff 文件名
查看我们提交历史(以便确定要回退到哪个版本。):git log
查看我们提交历史(单行显示):git log--pretty=oneline
回退到上一个版本:git reset --hard HEAD^
回退到上上一个版本:git reset --hard HEAD^^
回退到100个之前的版本:git reset --hard HEAD~100
回退到指定版本:git reset --hard 版本号
(版本号也就是git log–pretty=oneline前面显示的id,只需要记住前几位即可)
查看命令历史(用来重返未来):git reflog
用版本库里的版本替换工作区的版本,无论工作区是修改还是删除,都可以“一键还原”:git checkout
删除一个文件:git rm 文件名
提交到远程仓库: 1、在远程创建一个与本地仓库名一致的仓库 2、git remote add origin git@github.com:用户名/仓库名.git 3、git push -u origin master
第一步:设置用户名和邮箱,并且生成秘钥 不要密码的话直接一直Enter就行!
bashgit config --global user.name "你的名字"
git config --global user.email "你的邮箱"
ssh-keygen -t rsa -C "你的邮箱"
第二步:到git仓库,添加秘钥
如果你没有改变秘钥的生成路径,那么通过家目录的.ssh
下通过cat命令应该可以看到生成的秘钥,添加到GitHub(这里以Github为例)的秘钥中!
第三步: ssh -T git@github.com
测试一下通不通,不通就是ssh-agent -s
ssh-add ~/.ssh/id_rsa
操作这两步
第四步:把代码clone下来,使用git clone
命令将仓库拷贝下来!
git init
git init [project-name]
git clone [url]
git config --list
git config -e [--global]
git config [--global] user.name "[name]"
git config [--global] user.email "[email address]"
git add [file1] [file2] ...
git add [dir]
git add .
git rm [file1] [file2] ...
git rm --cached [file]
git mv [file-original] [file-renamed]
git commit -m [message]
git commit [file1] [file2] ... -m [message]
git commit -a
git commit -v
*使用一次新的commit,替代上一次提交如果代码没有任何新变化,则用来改写上一次commit的提交信息git commit --amend -m [message]
git commit --amend ...
git branch
git branch -r
git branch -a
git branch [branch-name]
git checkout -b [branch]
git branch [branch] [commit]
git branch --track [branch] [remote-branch]
git checkout [branch-name]
git branch --set-upstream [branch] [remote-branch]
git merge [branch]
git cherry-pick [commit]
git branch -d [branch-name]
git push origin --delete
、git branch -dr
git tag
git tag [tag]
git tag [tag] [commit]
git show [tag]
git push [remote] [tag]
git push [remote] --tags
git checkout -b [branch] [tag]
git status
git log
git log --stat
git log --follow [file]
、git whatchanged [file]
git log -p [file]
git blame [file]
git diff
git diff --cached []
git diff HEAD
git diff [first-branch]...[second-branch]
git show [commit]
git show --name-only [commit]
git show [commit]:[filename]
git reflog
git fetch [remote]
git remote -v
git remote show [remote]
git remote add [shortname] [url]
git pull [remote] [branch]
git push [remote] [branch]
git push [remote] --force
git push [remote] --all
git checkout [file]
git checkout [commit] [file]
git checkout .
git reset [file]
git reset --hard
git reset [commit]
git reset --hard [commit]
git reset --keep [commit]
git revert [commit]
git archive
git stash
git stash pop
git stash list
git stash clear
本文作者:Tim
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!