未加星标

A Guide to Using Git in PyCharm Part 2

字体大小 | |
[开发(python) 所属分类 开发(python) | 发布者 店小二04 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏

This post is part 2 of a multi-part series intended to describe how to use PyCharm’s integrated Git (version control) features.

In my previous PyCharm post (Part 1) , I described how to get started using Git in PyCharm, including:

Creating a local git repository Adding and commiting files to a git repository Making and committing changes to a python file

In this post, I will describe:

Creating branches Merging branches

These are extremely valuable features of Git, as they allow you to create a new version of your code to modify and evaluate before permanently integrating the changes into the master version of your code.

The following tutorial will assume you already have PyCharm and Git installed, and have a Github account. It also assumes you have a git repository to start with. Follow my steps in thefirst blog post if you don’t already have a git repository.

Create a new branch by right clicking on yourrepository project folder, and in the menu select Git >Repository >Branches, as is shown below.


A Guide to Using Git in PyCharm   Part 2

Select “New Branches” and then enter the name of the new branch in the box (see below for how I named the example branch):


A Guide to Using Git in PyCharm   Part 2

You can now see in the version control window that a new branch called “example_branch_1” has been created as a branch from the master branch (you can access this by clicking “version control” window at the bottom).


A Guide to Using Git in PyCharm   Part 2

Importantly, PyCharm has now placed you on the new branch (“example_branch_1”). Any changes you make and commit, you are making to the branch, not to the master (the one you started with).

First, right-click on the python file and select Git > Add.

Now, make some modifications to the python file on this branch.

In the menu at the top of the screen, select VCS > Commit changes.

In the menu that appears, provide a message to attach to your commit so you know later what changes you made. You can double click on the file name in the window (e.g., on the “blog_post_file.py” file) to review what changes have actually been made. If you like the changes, select“Commit”.


A Guide to Using Git in PyCharm   Part 2

In the menu at the very bottom of the screen to the right, you can now go back and “check out” the master branch. Just click master > Checkout, as is shown below.


A Guide to Using Git in PyCharm   Part 2

What now appears on your screen is the previous version of the “blog_post_file.py” file, before the function was modified, as is shown in the image below.


A Guide to Using Git in PyCharm   Part 2

The version control menu at the bottom explains the structure (and dates/times) of the master and branches.

You can now go back to the example branch if you want using the same feature.

This feature allows you to quickly snap to different branches that are being modified, and see how they are different. (This feature is also accessible from the menu at the top of the screen through VCS >Git > Branches).

If you want to merge your changes to your local master, do the following. From the master branch, you can now select “example_branch_1” in the same menu shown to the bottom right below. This time select “Merge” rather than “Checkout”. Your changes will now be merged onto the master branch, and the modified function will now appear on both the master and the example branch.


A Guide to Using Git in PyCharm   Part 2

I will continue to discuss PyCharm’s Gitfeatures in future posts in this series.

本文开发(python)相关术语:python基础教程 python多线程 web开发工程师 软件开发工程师 软件开发流程

主题: Git
分页:12
转载请注明
本文标题:A Guide to Using Git in PyCharm Part 2
本站链接:http://www.codesec.net/view/483214.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 开发(python) | 评论(0) | 阅读(34)