git checkout java
grego@gregoo:mygo$ git checkout origin/test Note: checking out 'origin/test'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b <new-branch-name> HEAD is now at be427c9... Create README.md grego@gregoo:mygo$ git checkout master Switched to branch 'master' Your branch is up-to-date with 'origin/master'. grego@gregoo:mygo$ git branch * (HEAD detached from be427c9) master test grego@gregoo:mygo$ git branch -r origin/HEAD -> origin/master origin/master origin/test grego@gregoo:mygo$ git push origin HEAD:test Username for 'https://github.com': ningxin1718 Password for 'https://ningxin1718@github.com': Counting objects: 3, done. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 313 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To https://github.com/ningxin1718/mygo.git be427c9..9a48c56 HEAD -> test
git log 退出 按 qgit
git回退github
git reset --hard <版本号> // 注意使用 --hard 参数会抛弃当前工做区的修改 // 使用 --soft 参数的话会回退到以前的版本,可是保留当前工做区的修改,能够从新提交 为了覆盖掉远端的版本信息,使远端的仓库也回退到相应的版本,须要加上参数--force git push origin <分支名> --force
git操做bash
1. git add 添加 多余文件 这样的错误是因为, 有的时候 可能 git add . (空格+ 点) 表示当前目录全部文件,不当心就会提交其余文件 git add 若是添加了错误的文件的话 撤销操做 git status 先看一下add 中的文件 git reset HEAD 若是后面什么都不跟的话 就是上一次add 里面的所有撤销了 git reset HEAD XXX/XXX/XXX.java 就是对某个文件进行撤销了 2. git commit 错误 若是不当心 弄错了 git add后 , 又 git commit 了。 先使用 git log 查看节点 commit xxxxxxxxxxxxxxxxxxxxxxxxxx Merge: Author: Date: 而后 git reset commit_id over PS:尚未 push 也就是 repo upload 的时候 git reset commit_id (回退到上一个 提交的节点 代码仍是原来你修改的) git reset –hard commit_id (回退到上一个commit节点, 代码也发生了改变,变成上一次的) 3.若是要是 提交了之后,可使用 git revert 还原已经提交的修改 这次操做以前和以后的commit和history都会保留,而且把此次撤销做为一次最新的提交 git revert HEAD 撤销前一次 commit git revert HEAD^ 撤销前前一次 commit git revert commit-id (撤销指定的版本,撤销也会做为一次提交进行保存) git revert是提交一个新的版本,将须要revert的版本的内容再反向修改回去,版本会递增,不影响以前提交的内容。
…or create a new repository on the command line echo "# test" >> README.md git init git add README.md git commit -m "first commit" git remote add origin https://github.com/ningxin1718/test.git git push -u origin master …or push an existing repository from the command line git remote add origin https://github.com/ningxin1718/test.git git push -u origin master …or import code from another repository You can initialize this repository with code from a Subversion, Mercurial, or TFS project.
step1,在本地新建分支 git branch newbranch step2:把本地分支push到远程 git push origin newbranch step3:切换到该分支 git checkout newbranch step4:查看本地修改 git status step5:添加本地修改 git add . step6:commit修改 git commit -m 'XXXX'
拉取远程分支 git fetch origin test git checkout -b test origin/test