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