Git与Arc重用命令(不断更新)

来源:互联网 发布:bat执行java程序 编辑:程序博客网 时间:2024/06/07 01:21

Git常用命令小结

  • git branch [name] 创建本地分支
  • git checkout [name] 切换本地分支
  • git add -u 只把修改的文件添加到索引库
  • git fetch 下载最新项目并且比较与最新项目的不同
  • git - -help 查看帮助文档
  • git reset - -hard 重置代码到分支之前的状态
  • git rebase [branchname] 合并分支(eg:git rebase orign/master)
  • git reset - -hard commit_id 撤销commit到提交的id
  • git tag -a v0.1.2 -m “0.1.2版本 创建附注标签
  • git push - -tags 推送所有本地tag到远程服务器
  • git branch -m oldname newname 重命名本地分支
  • git push - -delete origin branchname 删除远程分支

修改远程仓库

  • git remote rm origin
  • git remote add origin git@git.oschina.net:fuwenjiang/FirstGit.git

git 多个commit合并

 git rebase -i HEAD~2  

1.表示合并最近的2个提交

pick b76d157 b  pick a931ac7 c  # Rebase df23917..a931ac7 onto df23917  #  # Commands:  #  p, pick = use commit  #  r, reword = use commit, but edit the commit message  #  e, edit = use commit, but stop for amending  #  s, squash = use commit, but meld into previous commit  #  f, fixup = like "squash", but discard this commit's log message  #  # If you remove a line here THAT COMMIT WILL BE LOST.  # However, if you remove everything, the rebase will be aborted.  # 

2.把pick修改成squash就可以去掉这个commit,合并到其他commit中了


Git单个项目配置命令小结

git config user.name "Your Name Here"git config user.email your@email.com

Git全局配置命令小结

  • 查看Git全局配置信息
git config -l   
  • 提交代码的log里面会显示提交者的信息
 git config --global user.name [username] git config --global user.email [email]
  • 配置git编辑器
 git config --global core.editor notepad++
  • 配置git比较工具
 git config --global merge.tool vimdiff
  • 在git命令中开启颜色显示
 git config --global color.ui true
  • 配置几个常用的log命令
    git lg1 和 git lg2 两条 命令,可以比较方便的查看 commit。
$ vim ~/.gitconfig## insert [alias]    lg1 = log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all    lg2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n''          %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' -10 --all    lg = !"git lg1" 

注意:-10 代表最近的十条 ;–all代表所有分支

Using WinMerge as the git Diff/Merge Tool on Windows 64bit

[mergetool]    prompt = false    keepBackup = false    keepTemporaries = false[merge]    tool = winmerge[mergetool "winmerge"]    name = WinMerge    trustExitCode = true    cmd = "/c/Program\\ Files\\ \\(x86\\)/WinMerge/WinMergeU.exe" -u -e -dl \"Local\" -dr \"Remote\" $LOCAL $REMOTE $MERGED[diff]    tool = winmerge[difftool "winmerge"]    name = WinMerge    trustExitCode = true    cmd = "/c/Program\\ Files\\ \\(x86\\)/WinMerge/WinMergeU.exe" -u -e $LOCAL $REMOTE

ARC命令小结

  • arc diff Review代码
  • arc land Review通过后提交代码(建议在提交前先git fetch一次解决冲突)

产生密钥

Mac用户打开 Terminal,Windows用户打开 Git Bash。

首先检查是否有密钥存在:

$ ls -al ~/.ssh

如果你看到了类似下面的结果,说明已经有密钥了,直接前往第三步

id_dsa.pubid_ecdsa.pubid_ed25519.pubid_rsa.pub

执行以下命令创建密钥:

$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

程序会提示选择密钥保存位置,直接按回车选择默认地址即可。

接下来需要输入密钥的密码。

当你看到类似这样的文字,就成功啦:

Your identification has been saved in /Users/you/.ssh/id_rsa.Your public key has been saved in /Users/you/.ssh/id_rsa.pub.The key fingerprint is:01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example.com

添加密钥
找到刚才生成密钥目录的 id_rsa.pub (注意.pub)文件,把它的正文复制出来,你可以使用如下命令复制:

$ pbcopy < ~/.ssh/id_rsa.pub (Mac用户)$ clip < ~/.ssh/id_rsa.pub (Windows用户)

然后访问项目中需要密钥的位置,填写一个合理的名字,并把密钥粘贴到里面即可。

0 0
原创粉丝点击