ssh-keygen -t rsa -C "[email protected]" cat ~/.ssh/id_rsa.pub Add ssh key to webpage Then test whether ssk works ssh -T [email protected] Welcome to Git@OSC, yourname! git help http://git.mydoc.io/?t=154712 http://www.liaoxuefeng.com/ View username and email address: $ git config user.name $ git config user.email Modify username and email address: $ git config --global user.name "username" $ git config --global user.email "email" clone git clone git|http project address upload a project initialize git git init touch .gitignore came .gitignore git add . //Add to index git rm -r --cache .idea //delete index git commit -m "init" git reset HEAD filename undo the commit git update-index --assume-unchanged filename force ignore a file --Associate the remote address git remote add origin ...git --delete remote host address git remote rm origin --pull ignore unrelated history git pull origin master --allow-unrelated-histories git push -u origin master commits the code to the remote master branch --------bug-------------- The newline character in windows is CRLF, and the newline character in Linux is LF, so a prompt appears when executing add . The solution: [plain] view plain copy on CODE to view the code slice derived to my code slice $ rm -rf .git // delete .git $ git config --global core.autocrlf false // disable automatic conversion Then re-execute: [plain] view plain copy on CODE to view the code slice derived to my code slice $ git init $ git add . rm -rf .git delete git files
How to automatically remember passwords in git remote http(s) mode
In the https method, you need to enter the password every time. According to the following settings, you can enter it once without the trouble of manually entering the password and enjoy the speed brought by https. Follow the settings below to remember your password for fifteen minutes: git config --global credential.helper cache If you want to customize the remembered time, you can do this: git config credential.helper 'cache --timeout=3600' //Remember here is an hour, if you need it Other time, please modify 3600 to the time you want to modify, the unit is seconds You can also set a long-term remember password: git config --global credential.helper store Or modify the address of the warehouse and bring your account password http://yourname:[email protected]/name/project.git //Note that the code cloud platform supports both personal addresses and email addresses. When using email addresses, please replace the @ symbol with %40 If you want to replace the ssh address you originally used with an http(s) address, you can execute the following command: //Delete the original ssh warehouse address git remote rm origin //origin represents the alias of the repository of your original ssh address //Add the warehouse of the http address git remote add origin http://git.oschina.net/username/project.git //Modify the name of the remote repository git remote rename origin org
Use of git branches
create branch git checkout dev show branch name git branch -r|-a|-v switch branch git checkout origin dev --merge branch git merge dev --branch creation and merging git checkout -b dev //luobing //Switch and create a new branch luobing git push (-u) origin dev //push local dev branch to remote branch git branch (-u | --set-upstream-to=origin/dev ) origin/dev //The default is associated with the local dev delete branch git branch -d dev // delete local branch git push origin --delete dec_caoyw //delete remote branch git branch -m dec_caoyw dev_caoyw //Modify the local branch name To restore the deleted branch, first check the log to find the commitid and then git branch to retrieve the new branch git log -g commit 3eac14d05bc1264cda54a7c21f04c3892f32406a Reflog: HEAD@{1} (fdipzone <[email protected]>) Reflog message: commit: add test.txt Author: fdipzone <[email protected]> Date: Sun Jan 31 22:26:33 2016 +0800 git branch recover_branch_abc 3eac14d05bc1264cda54a7c21f04c3892f32406a ---fetch git fetch origin dev:dev git diff dev git merge dev --pull git pull origin dev
Use of git tags
Add a label git log --oneline View log git tag -a v0.1 i Input label remarks are generally the first 7 digits of commit can also git tag -a v0.2 -m "v0.2 version bug fixed" Submit tags to remote repository git push origin --tags git pull origin v0.1 Show label information git show v0.1 switch tab git checkout v0.1 list tags git day delete local tag git tag -d tagname delete remote tag git push origin :tagname
Branch merge error then rollback Create an empty branch in GIT git checkout --orphan doc then merge the code git chekcout --orphan test1.2.0.6.1 Allow commits without associated history git merge test1.2.0.6 --allow-unrelated-histories push remote branch git push org test1.2.0.6.1 git rebase test1.2.0.6 back to delete this branch git cherry-pick <commit id> How to put committed commits from one branch to another git reset --hard commitId git revert git diff test1.2.0.6 test1.2.2.0.6.1 --cached git diff test1.2.0.6 test1.2.2.0.6.1 --staged git add . git rm -rf --cache .filename If you submit it later, you can use git revert Revert committed changes The commit and history before and after this operation will be retained, and this revocation will be regarded as the latest commit git revert HEAD undo the previous commit git revert HEAD^ undo previous commit git revert commit-id (revocation of the specified version, the revocation will also be saved as a commit) Git revert is to submit a new version, and reverse the content of the version that needs to be reverted, and the version will be incremented without affecting the previously submitted content. git merge --no-ff saves your previous branch history. Can better view merge history and branch status. git merge will not display features, but only keep a single branch record.