Git笔记

Git -- How to manage your code

Control version system

Repo -- online

           -- local



git clone: copy

git pull: git fetch + git merge


Everytime you change the repo, you will get a commit number.


How to create a git repo

(in the local)

git init

git remote add origin [URL that you get from github.com]

How to put your local codes to online repo (in the local)

git add file1 file2  // just choose files, not yet save

git status

git commit -m "descriptive infomation"    // I want to save these files for change, add some message for log. not yet upload

git push [repo] [branch]  // such as git push origin master. standard repo is origin, standard branch is master.



fork, that branch will be belongs to you. [differ from the original 作者]

在页面上fork

git remote add upstream [address]

若是同一个作者,只是想要另一个分支,则,branch

git checkout -b dualArms   //create a new branch. -b means branch, followed by a new branch name




实用:已验证:

首次添加本地git目录:

     > cd MATLAB/parallel_RCBHT/

     > git init

     > git remote add origin https://github.com/drinkcor/parallel_RCBHT.git

     > git add wrenchCallback.m testForRealTimeComingData.m

     > git commit -m "two codes test code for local variables in parfor loop"

     > git push -u origin master

     > git status






git checkout master   // switch to branch master

fast forward: git merge dualArms  // merge dualArms to origin

git branch -d dualArms   // the branch dualArms will be disappeared.

若被删除的分支有一些工作没有被合并到master上的话,会提醒,但是若你仍旧想要删除的话,使用-D替代-d做参数即可。



但是上述命令只能删除本地分支,若想删除远程上的分支的话,还需要在本地执行以下命令:

git push origin : dualArms

代表将本地的空的分支提交到远程上,自然也就删除了远程的分支。




如果在当地切换了分支,如git checkout dualArm,那么本地的代码也会变化为dualArm分支下的代码。


如果在本地创建了新的分支,如git branch realtime,此时就可以有add, commit等操作了,但是远程的Repo上并不会有。因此需要git push -u origin realtime才可以将当前分支的所有内容添加到远程Repo上。之后的每次提交都可以用 git push origin realtime即可。


git diff FILENAME可以看到当前版本的文件和历史版本的不同之处,但是界面不友好,而meld 是最好用的文件比较工具。让 git diff 使用 meld 的方法为:

1、安装meld:
$ sudo apt-get install meld

2、创建 ~/bin/git-meld.sh 文件,内容为:
#!/bin/bash
meld $2 $5

3、让git-meld.sh可被执行:
$ chmod +x ~/bin/git-meld.sh

4、配置git使用meld:
$ git config --global diff.external ~/bin/git-meld.sh

然后今后使用 git diff 时,就会自动调用 meld 了

注意:做个个shell的原因是GIT会送7个参数给Meld,但是Meld只需要两个参数,两个需要比较的文件名。所以不能直接用Meld



ubuntu, git push origin <branch_name>, 错误 fatal:could not read Username for 'https://github.com':No such file or directory。如何解决?
解决方法:原来是终端出现了点毛病,导致我没办法输入github的用户名和密码。退出终端,重新提交,就可以输入用户名和密码,就不会有这个错误了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值