1:查看远程仓库地址:
git remote –v
2:查看当前分支:
git branch -a
* fourBranch
master
remotes/origin/fourBranch
remotes/origin/HEAD -> origin/master
remotes/origin/fourBranch
remotes/origin/healthBranch
remotes/origin/master
remotes/origin/threeBranch
3:切换分支
切到fourBranch分支:git checkout fourBranch
当使用git checkout 切换分支时,提示you need to resolve your current index first,使用如下命令即可解决。
git reset --merge
若提示有冲突,且当前代码修改的东西不重要,则可代码回退
git log
git reset --hard ee5012bexxxxxxxxxxxxxxxxxxxxxxxxx
git pull - git pull origin master
4:拉代码
git clone
5:把代码更到最新
git pull : 未改动代码的前提下更到最新 - git pull origin master
6:更新单个文件:cd到该文件的路径下 git checkout xxx//xxx文件名
7:提交
查看当前目录下的改动文件 git status ./
查看某文件的改动点 git diff xx.xx
git commit -m '[Feature] xxx' //新增
git commit -m '[BugFix] xxx' //修改
git push origin HEAD:refs/for/分支名字(master或其他) - git push origin master
8.
删除文件
git rm test.file
git commit -am "delete test.file"
删除文件夹
git rm -r文件夹
git commit -m "delete work”
git add -A 提交所有变化: 把当前文件夹内所有改动、新增、删除的文件都提交
git add -u 提交被修改(modified)和被删除(deleted)文件,不包括新文件(new)
git add .
当前文件夹内所有改动、新增的文件都化提交到暂存区,但不包括被删除的文件
git rm --cached 文件名//把暂存区中该文件的状态改为delete,意为删除该文件
git rm --cached xxx.java
9.从版本库剔除已经被tracked 的文件 (git rm与git rm --cached)
当我们需要删除暂存区或分支上的文件, 同时工作区也不需要这个文件了, 可以使用 git rm file_path
当我们需要删除暂存区或分支上的文件, 但本地又需要使用, 只是不希望这个文件被版本控制, 可以使用 git rm --cached file_path
file_path 为文件路径
10:
git log后
查看最新的commit:git show
查看指定commit hashID的所有修改:git show commitId
查看某次commit中具体某个文件的修改:git show commitId fileName
11. git diff后按q即可退出
10. push的时候提示 remote: Permission to xxx.git denied to xxx.
windows: git push 报错:remote: Permission to XXXA/xxxx.git denied to XXXB
mac: remote: Permission to .git denied to user.
11.
查看用户名:git config user.name
查看用户邮箱:git config user.email
修改用户名:git config --global user.name "Your_username"
修改用户邮箱:git config --global user.email "Your_email"
12. git放弃本地文件修改
13.远程创建分支后,本地更新:git fetch
14. git stash save "save message" : 暂存
git stash apply:获取暂存的内容
对新增文件,要先git add,再git stash save "lala"
15. Enter passphrase for key '/c/Users/Administrator/.ssh/id_rsa'
16. ERROR: commit c0d5d8b: missing Change-Id in message footer remote
git push时,出现上述错误,按提示来:
gitdir=$(git rev-parse --git-dir); scp -p -P 29418 xxx:hooks/commit-msg ${gitdir}/hooks/
git commit --amend --no-edit
再重新git push即可