获取Git配置信息,执行以下命令: git config --list
# Add the changes to the index and commit
git add . && git commit -m "More chaanges - typo in the commit message"
把数据传到服务器
git push origin
从服务器取数据
git pull origin
通过git amend命令,我们可以修改最后提交的的信息
git commit --amend -m "More changes - now correct"
git commit --amend 有时候我们提交完了才发现漏掉了几个文件没有加,或者提交信息写错了。想要撤消刚才的提交操作,可以使用--amend 选项重新提交
Commit the changes, -a will commit changes for modified files but will not add automatically new files
git commit -a -m "These are new changes"
给git commit 加上-a 选项,Git就会自动把所有已经跟踪过的文件暂存起来一并提交,从而跳过git add 步骤
git remote add命令为仓库添加一个短名称 git remote add origin ../remote-repository.git
git remote add origin git@127.0.0.1:/opt/git/napoli.git
git remote show origin 查看远程仓库信息
命令查看已经存在的远端仓库
git remote
git remote -v
# See the current status of your repository
# (which files are changed / new / deleted)
git status 显示还没有暂存起来的改动 暂存前后的变化
# Show the differences between the uncommitted files
# and the last commit in the current branch
git diff
git rm --cached readme.txt 把文件从Git 仓库中删除(亦即从暂存区域移除),但仍然希望保留在当前工作目录中。换句话说,仅是从跟踪清单中删除。
git rm log/\*.log 删除所有log/目录下扩展名为log 的文件
# Show the history of commits in the current branch
git log -p -2 显示最近提交的两次内容差异
# This starts a nice graphical view of the changes
gitk --all
查看
当前所有分支
的清单:
git branch -a
看各个分支最后一次commit 信息:git branch -v
删除分支
git branch -d
Switch to the testing branch :
git checkout testing
新建
并切换到该分支 git checkout -b master origin/master
git checkout filename将会删除该文件中所有没有暂存和提交的改动,这个操作是不可逆的。
git查看某个文件的修改历史
git log --pretty=oneline 文件名
显示具体的某次的改动的修改
git show 356f6def9d3fb7f3b9032ff5aa4b9110d4cca87e
git reset
--hard:重设(reset) index和working directory
--soft:index和working directory中的内容不作任何改变,仅仅把HEAD指向<commit>
--mixed:仅reset index,但是不reset working directory.这个模式是默认模式
git reset HEAD可以用来清除已经add到缓存区但是不想进一步提交的内容。
另一种方式是用git rm --cached,选项--cached表明是清除缓存区,然后不动工作目录树。
创建git仓库
在本地建一个库
git init
git add .
&&git
commit -m "Initial git repository"
git remote add origin git@github.com:itantek/mantis-scrumboard.git
git remote add origin https://github.com/itantek/mantis-scrumboard.git
git push -u origin master
创建远程库
git clone --bare . ../remote-repository.git
git clone git@github.com:itantek/mantis-scrumboard.git