您的位置:首页 > 编程语言

git的使用方法:回退本次commit,提交代码到另一个远程仓库,修改远程仓库地址

2017-08-09 17:58 836 查看

1. git创建本地分支:

git branch branchName #branchName 分支的名称


2. git修改前一次commit的message

git commit -a --amend -m "my message here"


注意:如果该comment已经push到远程库中,则还需要进行一次以下操作:

git push --force-with-lease origin master


5.git删除本地commit,回退到前几次commit

Step1:使用 ”Git log“ 命令 找到 想要撤销的操作之前的一次提交的commit id ;

$ git log
commit 3e130936be133bab0fa9ee2586b042611dc12e1f
Author: wei.sun <wei.sun@touchair.cn>
Date:   Wed Aug 9 10:34:42 2017 +0800

modify readme.md

commit 4dc838ef898a907ea9c1fe3ad851a153c3f3ed0d
Author: wei.sun <wei.sun@touchair.cn>
Date:   Wed Aug 9 09:35:40 2017 +0800

remove

commit ae5346f77ac3a79dcababc16bcd61560b3d4b1cd
Author: wei.sun <wei.sun@touchair.cn>
Date:   Wed Aug 9 09:31:18 2017 +0800

remove touchair-libraries


我想删除最近的两次commit:那就需要选择倒数第三次的commit id

即:ae5346f77ac3a79dcababc16bcd61560b3d4b1cd

Step2:

使用如下两个命令撤销提交:

git reset --hard  ae5346f77ac3a79dcababc16bcd61560b3d4b1cd #如果还没有push到远程服务器只需要执行这一步
git push origin HEAD --force


如果 git reset –hard ae5346f77ac3a79dcababc16bcd61560b3d4b1cd 之后发现commit没有回退,就需要切换本地分支之后在执行reset命令:

git checkout master #master为本地master分支


<
aa36
strong>6.从一个git仓库提交代码到另一个仓库[/b]

以tigase目录为例:从git://repository.tigase.org/git/tigase-xmltools.git这个地址clone tigase-xmltools项目到本地:

现在想把这个项目push到公司的gitlab服务器上:

Step1: 将仓库origin_repo_b的URL添加到工作仓库的remote中:

git remote add origin_repo_b gitAdress
#gitAdress是git仓库地址
#origin_repo_b:自定义的仓库名字,只要与现有的remote名不重复既可


此时查看项目git的config文件,文件底部会多出以下:

[remote "origin_repo_b"]
url = gitAdress
fetch = +refs/heads/*:refs/remotes/origin_repo_b/*


Step2:将代码push到远程origin_repo_b 上

git push origin_repo_b master #master是你本地的branch


可用 git clone gitAdress 查看push是否成功

Step3:修改tigase-xmltools项目文件,上传到origin_repo_b上

git push origin_repo_b master #待检验


或者用IDEA,选项路径:VCS>>Git>>push


>Git>>push" title="">

7.git修改远程仓库地址

git修改远程仓库地址

方法有三种:

1.修改

git remote origin_repo_b set-url gitAdress


2.先删后加

git remote rm origin_repo_b
git remote add origin_repo_b gitAdress


3.直接修改config文件
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: