关于GIT的一些操作

git 常用

1.清理本地无效分支,当代码无法pull,push时候;

  ``` git remote prune origin;```

2.合并master分支,更新当前分支;

  ```

  2.1 git checkout master;

  2.2 git pull;

  2.3 git checkout 分支名;

  2.4 git pull;

  2.5 git merge master;

  2.6 git push -u origin 分支名;

  ```

3.合并到master 分支;

  ```

  3.1 git pull 分支名;

  3.2 git checkout master;

  3.3 git merge 分支名;

  3.4 git push -u origin master;

  ```

4.无法push解决办法;

  ```

  4.1 git pull --rebase origin 分支名;

  4.2 git pull

  4.3 git push

  由于两者不同步,但是普通的merge、pull和push都不行,因此需要特殊的pull,进行合并然后在进行push,

  git pull --rebase origin master

  将远程文件同步下来。

  然后再执行推送

  git push -u origin master

  ```

5.撤销 add

  ``` git reset HEAD ```

6.撤销 commit

  ``` git reset --soft HEAD^ ```

7.撤销 push

  ```

  7.1. git log

  7.2. git reset --soft 43dc0de914173a1a8793a7eac31dbb26057bbee4

  7.3. git push origin master --force

  ```

8.强制推送版本

  ``` git push origin XXXXXX --force 或者  git push origin HEAD --force ```

9.查看状态

  ``` git status ```

10.使用 git add 命令将想要快照的内容写入缓存区, 而执行 git commit 将缓存区内容添加到仓库中。

git add  '目录' 或者 git add . 全部提交

$git commit -m '提交代码注释'

git reset HEAD  取消已缓存区的内容

git onreset --hard 版本号

11.删除

git rm readme.md

12.配置别名方便使用

$ git config --global alias.st status

$ git config --global alias.ci commit

$ git config --global alias.co checkout

$ git config --global alias.br branch

$ git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

13.分支管理

创建分支

``` git branch mybranch```

切换分支

git checkout mybranch

创建分支并且切换

git checkout -b mybranch

删除分支

git branch -d mybranch

把分支push到远端仓库

git push origin mybranch

更新本地仓库至最新改动

git pull origin master

也可以使用fetch 和rebase 来进行分支更

git fetch origin

git rebase origin/master

14.撤销和修改 版本回退

git checkout --filename

git log 拿到版本号

git reset --hard 版本号回退到制定版本

未完待续~

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容