首页 / GIT / 工作中用到的 Git 命令行操作
工作中用到的 Git 命令行操作
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了工作中用到的 Git 命令行操作,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4311字,纯文字阅读大概需要7分钟。
内容图文
首先,在开发前要先新建一个分支,建分支前,要确定是基于哪个分支创建,一般是基于最新的 master。 ? 在自己新建的分支上就可以自由开发啦! ? 基于 master,执行命令:git checkout -b newbranch ?即新建分支成功! ?常用的git命令
git fetch?把代码更新到远程仓库副本 git rebase origin/master 将最新?master 的更新到当前分支? git commit –m “修改内容” 修改合并后 commit 信息 git push --force 每次 commit 记录更改后需要强制push(例:每次 rebase 之后,修改了 commit 记录,需要强制 push) ? 简易合并 commit 记录,两个 git 的命令是一样的 git rebase -i HEAD~2?把近两次提交记录重置合并 git reset --soft HEAD~2?把近两次提交记录重置合并 注意??:有些修改不想 commit,但是又想 rebase 时,使用 git stash 先暂时“隐藏”,rebase 结束后使用 git stash pop “显示”; ? Rebase 遇到冲突时 ? 根据提示修改冲突的文件 git status?查看修改文件 对于红色的文件进行?git add 操作 git add ‘冲突文件名称’ (例:git add /view/study/class1.vue 多个冲突文件时建议一个一个 add) 所有的冲突文件add完毕之后 git rebase --continue git push --force ? 如果有冲突暂时无法解决,先退出?rebase git rebase --abort 解决完冲突再进行?rebase 操作 ? 注意??:? ?- git fetch 是把代码更新到远程仓库副本(不同于暂存区的概念),也就是本地的远程仓库,一般情况下,git fetch origin 可以简写为 git fetch,直接用 git fetch 表示 fetch 所有的分支,git fetch origin 表示 fetch origin 这个仓库的所有分支
- 暂存区是指诸如 git add 之后代码存放的一个场所
- git rebase origin/master 之前可以执行 git fetch,保证将本地的 origin/master 更新到最新
pick 3084f5f DEV-1 xxx的第一次提交 pick fbe427f DEV-2 yyy的第一次提交 pick f33720a DEV-1 xxx的第二次提交 pick 50ae80d DEV-2 yyy的第二次提交 # Rebase 584512c..50ae80d onto 584512c (4 command(s)) # # 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 # x, exec = run command (the rest of the line) using shell # d, drop = remove commit # # These lines can be re-ordered; they are executed from top to bottom. # # If you remove a line here THAT COMMIT WILL BE LOST. # # However, if you remove everything, the rebase will be aborted. # # Note that empty commits are commented out ~ ~ ~ "~/iceworks-workspace/researchforce/.git/rebase-merge/git-rebase-todo" 23L, 815C
调整 commit 的顺序,将要 squash 成一个的 commit 放在相邻位置; 被 squash 的 commit 前面把 pick 改成 s (squash); 比如以下代码表示: “DEV-1 xxx的第二次提交” 的 commit 会被合到 “DEV-1 xxx的第一次提交” ; “DEV-2 yyy的第一次提交” 的 commit 会被合到 “DEV-2 yyy的第二次提交” ; ?
pick 3084f5f DEV-1 xxx的第一次提交 s f33720a DEV-1 xxx的第二次提交 pick 50ae80d DEV-2 yyy的第二次提交 s fbe427f DEV-2 yyy的第一次提交
这个编辑器是修改第一个 squash 的 commit 消息的:修改完成,保存退出(先切换到英文输入法状态,再点击下 esc,再输入 :wq。:w 保存???:q? 退出???:wq 保存退出)编辑器以后,会自动进如下一个编辑器: 编辑 commit 消息以后,保存退出; 会进入下一个编辑器,这个编辑器是修改第二个 squash 的 commit 消息的,操作同第一次。 ?
pick 3084f5f DEV-1 xxx的第一次提交 # This is a combination of 2 commits. # The first commit's message is: DEV-1 xxx的两次提交 # This is the 2nd commit message: # DEV-1 xxx的第二次提交 # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # Date: Thu Sep 5 19:05:46 2019 +0800 # # interactive rebase in progress; onto 584512c # Last commands done (2 commands done): # pick 3084f5f DEV-1 xxx的第一次提交 # s f33720a DEV-1 xxx的第二次提交 # Next commands to do (2 remaining commands): # pick 50ae80d DEV-2 yyy的第二次提交 # s fbe427f DEV-2 yyy的第一次提交 # You are currently editing a commit while rebasing branch 'clara/text-update' on '584512c'. # # Changes to be committed: # modified: src/layouts/BasicLayout/index.tsx # # Untracked files: # .DS_Store # .editorconfig # src/.DS_Store # ~ ~ "~/iceworks-workspace/researchforce/.git/COMMIT_EDITMSG" 31L, 909C? 此文,仅限于个人工作中的实践,不代表绝对正确!
内容总结
以上是互联网集市为您收集整理的工作中用到的 Git 命令行操作全部内容,希望文章能够帮你解决工作中用到的 Git 命令行操作所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。