LEARN GIT through blog
install the git bash
linux: pacman -S git
basic operation
mkdir learn
cd learn
git init ,git config –global user.name=””,….user.email=”” ; init repo and set name,pwd:
vim learn : create a file and use git to commit
git commit -m “writed some thing” : commit information
- git add file1
- git add file2
- git commit -m “multiply files”
- git status : if the file is changed,use this command to see status
- git diff readme.txt : see the details of the chang
- git add readme.txt : upload
- git commit -m “changed”
- git log
- git reset –hard HEAD^ ^:means your previous version==> ^^two previous version ==> HEAD^^^ == HEAD~3
git reset –hard 1094a (if you remember the id of the target version)
regret and don’t know the version id: git reflog
- git reflog : command history
- git checkout – readme.txt (!!!not –readme.txt It means switching to another branch)
- or use: git reset HEAD readme.txt
- rm test.txt
- git rm test.txt
- git commit -m “”
remote repository
how to connect to a remote reposity
- ssh-keygen -t ras -C “tassassin@sina.com“ : default directory is /user/home/.ssh
then copy the id_ras.pub to you github !
- git remote add origin https://github.com/MOIPA/tmp.git
- git push -u origin master //push content to remote server do it when every local changed
how to git clone
- git clone http://github.com/MPOIA/javaEE
how to clone specific branch
- git clone -b “branch” “url”
how to pull specific branch
- git checkout -b 本地分支名 origin/远程分支名
branches
- git checkout -b branchName(-b : create a branch and switch to it)
-b :equals two command:
a: git branch bname
b: git checkout bname - git branch (see branches)
- connflicts: solve it in person
a:git status : show conflicted files
b:vim conflicted files: show details
c: git log –graph –pretty=oneline –abbrev-commit :show branches merge status - git merge –no-ff : use this argument can show merge history in git graph command
- force delete unmerged branches : git branch -D bName
git stash (used to store the context)
- when developing in dev branch, a bug in master branch need to be solved. 2. git stash in dev branch 3. git checkout -b issue-101 to create a bugfix branch 4. after fixed, git checkout master then: git merge -m “bug fix issue 101” issue-101 5. git checkout dev , git stash pop to continue **conclusion: it is used for clean git , because you can’t push when have some unfinished work **
git push & git pull
git push origin(default name of remote repository) <branch>(can be master or other banch name) 2. if push failed,use git pull to get the newest update and solve the conflict 3. git pull : if failed and shows no tracking information use **git branch –set-upstream-to=origin/<branch> localBranchName
it failed because u don't connect ur local dev to remote dev
team work:
when work with a team, members only can get master branch and it’s default name is origin
now if we want to get a remote branch like dev: git checkout -b <lbname> origin/<bname>git rebase
make the git history become a straight line
TAG convient for managing (one tag means one release)
create tag
- git tag v1.0
- git tag : show tags
create tag for old version
- git tag v0.1 <71180d>
show tag details
- git show <v0.1>
create a tag with a readme
- git tag -a v0.8 -m “merged something” <0123d>
delete a tag
- git tag -d v0.1
push tag to remote
- git push origin v1.0 :push one tag
- git push origin –tags :push all tags
delete tag of remote
- git tag -d v1.0 (delete on local first)
- git push origin :refs/tags/v0.9 (inform remote)
if want to synchronize my respository to github and gitee
- git remote -v
- git remote rm origin
- git remote add github git@github.com:MOIPA/REpo.git
- git remote add gitee git@gitee.com:MOIPA/REpo.git
** if want to push to these two server **
- git push github master
- git push gitee master
configure
- git config –global color.ui true (high light color)
- config some files won’t commited to git
a: create a file .gitignore (store somefile names which will not be committed)
b: the file module can be download at officialSite - configure alias:
git config –global alias.<st> status - one good example:
git config –global alias.lg “log –color –graph –pretty=format:’%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset’ –abbrev-commit” - notice
all the configure are stored in .git/config
Problems
switch to ssh instead of https
- git remote -v : see connection
- git remote rm oringin :clear connection
- git remote add oringin git@github.com:MOIPA/REpo.git
error when test SSH connection
- ssh -t github.com : denied
- solution : ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
- then git push -u origin master