git 常见问题

1. 正常做项目:

git clone http://.....

git checkout your-dev-branch

scp -p -P port userid@ipaddress:hooks/commit-msg .git/hooks/

export EDITOR=vim

edit source code

git add . / git rm filepath

git commit .

edit commit-msg

git push -u origin your-dev-branch

2. 别人打了comment,自己需要打patch

fix comment issue

git add ./git rm filepath

git commit --amend

change commit-msg if necessary

git push -u origin your-dev-branch

3. 打算合并自己的代码,但是期间其他人合并了代码,需要修正conflict

git pull --rebase

fix conflict code

git add . / git rm filepath

git rebase --continue

git commit --amend

change commit-msg if necessary

git push -u origin  your-dev-branch

4. 在别人的代码上打patch

git clone http://.....

git fetch ssh://userid@hostname:port/gitpath refs/changes/num1/num2/num3 && git checkout FETCH_HEAD

scp -p -P port userid@ipaddress:hooks/commit-msg .git/hooks/

export EDITOR=vim

fix source code

git add ./git rm filepath

git commit --amend

change commit-msg if necessary

git push -u origin your-dev-branch

5. 将当前提交的开发代码片段搬到主分支,直接使用git cherry pick,注意只是当前提交的代码片段,而不是当前所有的差异代码

6. 将目前所有差异代码合并入主分支

git clone http://.....

git fetch ssh://userid@hostname:port/gitpath refs/changes/num1/num2/num3 && git checkout FETCH_HEAD

scp -p -P port userid@ipaddress:hooks/commit-msg .git/hooks/

export EDITOR=vim

git checkout dev-branch

git reset --hard

git pull

git checkout master

git reset --hard

git pull

git reset --hard origin/master     
git merge --no-ff --no-commit dev-branch

fix conlict code

git add . / git rm filepath
git commit . (可能会报错fatal: cannot do a partial commit during a merge)

如果报错则需要git commit -i * .

git push -u origin master

7. 放弃当前改动的代码

git reset --hard ----放弃所有文件改动

git pull

git checkout filepath ----放弃某一个文件改动

 

 

 

 

 

 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值