git笔记

1 Linux下Git和GitHub环境的搭建

第一步: 安装Git,使用命令 “sudo apt-get install git”

第二步: 创建GitHub帐号

第三步: 生成ssh key,使用命令 “ssh-keygen -t rsa -C "your_email@youremail.com"”,your_email是你的email

第四步: 回到github,进入Account Settings,左边选择SSH Keys,Add SSH Key,title随便填,粘贴key。

第五步: 测试ssh key是否成功,使用命令“ssh -T git@github.com”,如果出现You’ve successfully authenticated, but GitHub does not provide shell access 。这就表示已成功连上github。

第六步: 配置Git的配置文件,username和email

git config --global user.name “your name” //配置用户名

git config --global user.email “your email” //配置email

echo "# -MachineLearningInAction" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/username/demo1.git
git push -u origin master

##…or push an existing repository from the command line

git remote add origin https://github.com/username/demo1.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.

参考http://www.linuxidc.com/Linux/2014-03/97821.htm

tip:
Git设置为英文显示
echo “alias git=‘LANG=en_GB git’” >> ~/.bashrc
linux服务器git pull/push时提示输入账号密码之免除设置
https://www.cnblogs.com/orzlin/p/5613310.html

fatal: remote origin already exists.
先输入 git remote rm origin
再输入 git remote add origin …
git push -u origin master

git查看远程仓库地址
git remote -v

git add *
删除误上传的文件,并不删除本地文件
git rm --cached 1.ts

git checkout 命令详解
http://www.cnblogs.com/hutaoer/archive/2013/05/07/git_checkout.html

在日常的git操作中,git checkout——检出,是我们的常用命令。最为常用的两种情形是创建分支和切换分支。

在下面的命令中,使用了一些简写,在这里说明一下:

git st # git status
git ci  # git commit
git br # git branch
git co # git checkout
git mg # git merge
git line # git log --oneline

当然,你也可以直接在git中敲命令,将这些简写添加到git配置中

git config --global -e

然后,可以插入下面的配置:
复制代码

[alias]
    st = status
    co = checkout
    br = branch
    mg = merge
    ci = commit 
    md = commit --amend
    dt = difftool
    mt = mergetool
    last = log -1 HEAD
    cf = config
    line = log --oneline
    latest = for-each-ref --sort=-committerdate --format='%(committerdate:short) %(refname:short) [%(committername)]'

    ls = log --pretty=format:\"%C(yellow)%h %C(blue)%ad %C(red)%d %C(reset)%s %C(green)[%cn]\" --decorate --date=short
    hist = log --pretty=format:\"%C(yellow)%h %C(red)%d %C(reset)%s %C(green)[%an] %C(blue)%ad\" --topo-order --graph --date=short
    type = cat-file -t
    dump = cat-file -p


这样,你也就可以使用这些简写的命令咯。下面步入正题啊。

创建新分支:
git branch branchName
切换到新分支:
git checkout branchName
git push -u origin branchName


git add -A和 git add .   git add -u在功能上看似很相近,但还是存在一点差别

git add .    :他会监控工作区的状态树,使用它会把工作时的所有变化提交到暂存区,包括文件内容修改(modified)以及新文件(new),但不包括被删除的文件。
git add -u    :他仅监控已经被add的文件(即tracked file),他会将被修改的文件提交到暂存区。add -u 不会提交新文件(untracked file)。(git add --update的缩写)
git add -A    :是上面两个功能的合集(git add --all的缩写)

git clone 指定的分支
git clone -b branchName https://github.com/name/test1.git

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值