您的位置:首页 > 其它

GIT 在提交之前撤销add操作

2015-10-18 23:30 337 查看
git 在提交之前撤销add操作

问题:


在使用git时,在未添加.ignore文件前使用 git add . 将所有文件添加到库中,不小心将一些不需要加入版本库的文件加到了版本库中。由于此时还没有提交所以不存在HEAD版本,不能使用 git reset HEAD命令。

解决:

使用 git rm -r --cached .

ps:注意最后是有点的。

---------------------------------------改写最后一次提交---------------------------------------

git commit -m'改写最后一次提交'

git add forgotten_file //补上忘记提交的文件

git commit --amend

----------------------------------------remote--------------------------------------------

git remote add [shortname] //添加远程仓库

git remote -v //列出远程仓库

git remote show [remote-name] //列出远程仓库详细信息

git remote rename old-name new-name //远程仓库重命名

git remote rm [remote-name] //删除远程仓库

----------------------------------------fetch-----------------------------------------------

git fetch [remote-name] //将远端的数据拉到本地仓库,并不自动合并到当前分支,仍需手工合并。

---------------------------------------tag-------------------------------------------------------

git tag v1 //建立标签

git tag -a v1 -m '建立标签'

git show v1 //查看标签版本信息

----------------------------------[url=http://linux.chinaitlab.com/]linux
下自动补全功能------------------------------------

在git源码中 contrib/completion 目录中的 git -completion.bash 复制到自己的用户目录中。并把下面内容添加到你的 .bashrc文件中

source ~/.git-completion.bash

---------------------------------设置Git命令别名---------------------------------------------

git config --global alias.co checkout //设置checkout 命令别名

git config --global alias.br branch //设置branch 命令别名

git config --global alias.ci commit //设置commit 命令别名

git config --global alias.st status //设置status 命令别名

git config --global alias.last 'log -1 HEAD' //查看最后一次提交信息

git config --global alias.visual "!gitk" //启动gitk。运行外部命令,只需在命令前加上 ! 。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: