git使用中的几个冷门技巧

一、git远程删除分支后,本地git branch -a 还能看到

有时候,同事推了分支origin/test,测试完成后将本地(git branch -D test)和远端的该分支(git push origin --delete test)都操作删除,这时,我们本地使用命令git branch -a却还是能够看到这个分支,并能成功checkout。但其实你并不希望看到这个test分支:

$ git remote show origin  #显示所有分支,并提示其状态

  Remote branches:
    master                        tracked
    refs/remotes/originhttps/test stale (use 'git remote prune' to remove)

$ git remote prune origin  #全部予以删除(也可指定具体分支进行操作)

Pruning origin
URL: https://github.com/xxxxxx/testgit.git
 * [pruned] originhttps/test



二、如何把已经提交的commit, 从一个分支放到另一个分支

我们有时候会凌乱在几个分支中,把本来要提交到分支test的内容commit到了分支test2,此时,既不想在分支 test上重做,也不能合并过去,怎么办:

$git status
On branch test2
Your branch is ahead of 'originhttps/test2' by 1 commit.
  (use "git push" to publish your local commits)

而其实我希望将这个commit做到test1上面的
$ git checkout test1
$ git cherry-pick 50db69485
[test1 e7574ee] this is a mistack
 Date: Sun Mar 12 08:36:54 2017 +0800
 1 file changed, 1 insertion(+)
 create mode 100644 iwant2commit2test1




三、修改已经commit的内容

曾经包含敏感信息的内容直接commit的筒子们举个手,往往commit甚至push之后发现备注写错了字或者提交文件中有密码。这时还有救吗?

$ git show 2d91ccfcf
commit 2d91ccfcf8b25b27b7245077a7654eb799ff58f5
Author: XXXX <xxxxxxxxxxxx@126.com>
Date:   Sun Mar 12 08:49:31 2017 +0800
    typo in comment

diff --git a/sensitive_file b/sensitive_file
new file mode 100644
index 0000000..05e7a00
--- /dev/null
+++ b/sensitive_file
@@ -0,0 +1 @@
+this is my db password


继续修改文件内容后,git add 后执行

$ git commit --amend
$ git log
commit e84762041f68e210b65c463007d2349b86b92135
Author: XXXX <xxxxxxxxxxxxxxxxxx@126.com>
Date:   Sun Mar 12 08:49:31 2017 +0800
    changed the commit comment

$ git show e84762041f
commit e84762041f68e210b65c463007d2349b86b92135
Author: XXXX <xxxxxxxxxxxxxxxx@126.com>
Date:   Sun Mar 12 08:49:31 2017 +0800
    changed the commit comment
diff --git a/sensitive_file b/sensitive_file
new file mode 100644
index 0000000..9e0708f
--- /dev/null
+++ b/sensitive_file
@@ -0,0 +1 @@
+my db password deleted
$git push --force


------the end---

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在PyCharm使用Git可以方便地进行版本控制和团队协作。下面是使用PyCharmGit的一般步骤: 1. 配置Git:首先,确保你已经在计算机上安装了Git,并且在PyCharm配置了Git的路径。你可以在PyCharm的设置找到Git的配置选项。 2. 初始化Git仓库:在PyCharm打开你的项目,然后选择VCS(版本控制系统)菜单,点击"Import into Version Control",选择"Create Git Repository"。这将在你的项目文件夹初始化一个Git仓库。 3. 添加文件到版本控制:在项目视图,右键点击你想要添加到版本控制的文件或文件夹,选择"Git" -> "Add"。这将把文件添加到Git的暂存区。 4. 提交更改:在项目视图,右键点击你想要提交的文件或文件夹,选择"Git" -> "Commit Directory"。在弹出的对话框,输入提交信息并点击"Commit"按钮。 5. 查看提交历史:在底部的Version Control工具窗口,你可以查看提交历史记录。你可以看到每个提交的详细信息,并且可以比较不同版本之间的差异。 6. 推送到远程仓库:如果你想将你的更改推送到远程仓库(如GitHub),可以选择"Git" -> "Push"来进行推送操作。在弹出的对话框,选择要推送的分支并点击"Push"按钮。 这些是使用PyCharmGit的基本步骤。当然,还有其他更高级的功能,如分支管理、合并等,你可以在PyCharm的文档找到更多详细信息。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值