zoukankan      html  css  js  c++  java
  • pycharm版本控制

    转载至:http://blog.csdn.net/pipisorry/article/details/39897949

    [不了解git版本控制的可以阅读这篇 -  Git版本控制教程 - Git本地仓库]

    开启版本控制

    Click  >clickVersion Control. By default, the only root is<project>, and it is not mapped to any version control system.

    • First, click . In the Add VCS Directory Mapping dialog, click the ellipsis(省略) button, and choose thedirectory you want to put under version control. From the VCS drop-down list, select a version control system you are going to use (in our example, let it be Git):

    By the way, if you have several directories, you can map each of them to its own version control system, or leave some of them unversioned.

    Note:

    1. 如果Python workspace已经在Git版本控制下了,点击version control就会看到Directory下有提示unregistered roots:project_name,点击这个project,再点击+号就添加到版本控制中了。

    2. 新建的包都最好先通过这种方式加入到git版本控制下,再进行下面的操作。

    • Next, apply your new version control settings, and close the Settings dialog.设置git:将git添加到pycharm版本管理中来:settings > version control > git > path to git excutable > D:Gitingit.exe 选择git.exe的安装路径就可以了。

    How does it affect PyCharm's appearance?上述操作完成后pycharm界面的变化

    Something has changed. PyCharm now looks differently...Let's explore the changes in PyCharm's UI.

    • You see the new color code of the file Solver.py. Now it is brown, which means that the file exists, but is not yet added to the version control.
    • Changes tool window appears - you see its button along the lower border of PyCharm. Click this button to open the tool window, and see the list of unversioned files. Later we'll see what to do with them.
    • The VCS menu, and the VCS operations pop-up now show more commands. In particular, you see the commands that allow checking your changes in therepository(贮藏室), and updating the entire project. These commands aredenoted(表示) with the icons and respectively.
    • Same icons appear on the main toolbar.
    • A Git node appeared on the VCS menu, and on the context menus of the Project tool window and the editor. Have we selected a different version control system to associate with a directory, this node would be different (Perforce, CVS, etc.). This node contains VCS-specific commands.
    • In the Status bar, you see the Git widget - this is a Git-specific modification(修改).

    Putting a file under version control将某个文件加入到版本控制中(default中)(相当于git中添加到repository中的暂存区stage)

    1. 在changes窗口中添加:

    Look at the list of unversioned files in the Changes tool window:

    Select Solver.py, and pressCtrl+Alt+Ato add this file to version control: you see that the color code of the file changed - now it is green, which means that the file is added to version control, but not yet committed to therepository(贮藏室). The file moved to the new changelist with the name Default.

    2. 在左侧的project中添加:

    指定某个文件夹(包、项目) 1. 右键 > git > + / Add    或者 2. ctrl + alt + a

    Note:
    1. pycharm会自动git add,打开右边的changes窗口可以看到修改过的文件自动add到default中了。

    2. 要将已添加到git版本管理中的文件删除(不是删除文件,只是不添加到repository中的暂存区stage): changes窗口 > default > 1.  右键文件 > revert  或者 2.ctrl + alt +z
    3. 删除本地文件后:若添加到repository中的文件已push到远程,删除本地文件后,changes窗口会出现刚刚删除的改动,要push到远程才能将远程的文件也删除了。如果不push或者commit,那么删除的文件总在default文件list中,待commit状态。
    4. 删除本地文件后:可以通过changes窗口中的ctrl+alt+z撤销修改(删除)

    将文件提交到repository中(相当于git中提交到repository中的master)
    Now press Ctrl+K(or click button in the Changes tool window) to commit your changes:

    Next, enter your check-in comment(相当于git中的git commit -m "comment"中的comment参数), and finally click theCommit button:

    OK, the changes are checked in. The Default changelist is now empty, and the color code of the file nameSolver.py changed again - it becameblack, which means that there are nopending(在…期间) changes.

    Note:

    1. 上图中如果选择commit改为选择commit and push就可以在commit同时将代码提交到远程仓库github中。远程仓库设置见下面 pycharm版本远程控制 部分。注意push到哪个分支,在git中修改过当前分支可能反映到pycharm中也是那个分支。

    2. 将修改过的files push的另一种方法: 在当前文件中 > 右键 > Git > Repository > push > 选择push的位置/分支

    Files under .idea directory

    There are more unversioned files left. If you click the button in the Changes tool window, you will see that all these filesreside(住) in the directory.idea under the project root. However, we don't see this directory under the project root in the Project tool window.

    The files under this directory are the settings files of your project.It is recommended to place all of them, except one, under version control. So, do it as described in the previous section.

    Ignoring files要忽略的文件,不添加到版本控制中

    This only file that should be ignored, stores your workspace preferences; its name isworkspace.xml. The fileworkspace.xml is ignored by default. Open theIgnored Files page of the Settings dialog (Version Control→Ignored Files), and see the list of files ignored by version control by default:(相当于git中的.gitignore文件的作用)

    If you want more files to be ignored by your version control system, click , and then enter specific file name, or a mask, or a directory name. Refer to the pageConfiguring Ignored Files for details.

    Note:

    1. 在changes窗口中也可以confige ignored files{同上面提到的“Ignoring files要忽略的文件,不添加到版本控制中”} / show ignored files

    2. 在changes窗口 > unversioned files > 选择要ignore的文件 > 右键 > ignore也可以忽略文件

    Viewing changes in the editor在编辑器中查看变化

    Let's edit the source code: for example, rename a variable, remove a line, add a line. All the changes are marked in the left gutter:

    Click a line with a change - a pop-up window with a toolbar appears:修改代码后windows左边会出现一个pop-up,可以随时返回到修改前的状态。

    As you see, this toolbar helps doing many useful things: navigate between changes, view differences, roll the changes back, and put the previous version toclipboard(剪贴板).

    Refer to the page Using Change Markers to View and Navigate Through Changes in the Editor for details.

    By the way, the color code of the file name changed again - it became blue, which means that there arepending(未决定的) changes not yet committed to yourrepository(贮藏室). Since you already know how to commit changes, do it now - and see that the change markers in the left guttervanished(消失).文件提交到repository中的master之后,左边的pop-up就消失了。

    Getting up-to-date information from the repository从repository中获得最新的信息

    Suppose somebody else is working on the same project. Now you want to get the external changes locally.

    PyCharm, as usual, provides several ways to do it:

    • Press Ctrl+T
    • Click on the main toolbar
    • Choose VCS→Update Project...

    The action per se is VCS-agnostic. However, the dialog box that shows up when youinvoke(调用) updating, is VCS-dependent. It will be different, for example, forGit update and forPerforce update - compare the dialog descriptions.

    project中的文件显示颜色

    黑色表示已提交

    绿色表示刚修改过,正需要提交

    灰色表示被设置成ignore,不会提交的

    红色表示没有添加到版本控制中(或者当前文件所在文件夹在另一个.git管理下)

    [pycarm中给某个文件的父目录创建新的repository、创建新分支]

    http://blog.csdn.net/pipisorry/article/details/39897949

    pycharm版本远程控制

    [不了解git远程版本控制的可以参考这篇 -Git版本控制教程 - Git远程仓库]

    Two ways to share source code分享原代码的两种方法

    To publish your source code, you need write access to a remote storage, for example, to theGitHub storage.

    To initiate publishing, open the project described in the tutorial"Using PyCharm's Git integration locally" if it is closed. Your further actions depend on the selected strategy, since PyCharm provides two ways of sharing your source code.

    Note that all actions are performed with the current branch.

    Sharing on GitHub在github上分享代码

    On the main menu, choose VCS→Import into Version Control→Share project on GitHub:

    If you have your GitHub account properly configured, you will see the dialog box, where you have tospecify the repository name and optional description:

    Click Share - and behold your source code in a brand new remote repository.

    commit到本地repository中

    方法1. changes窗口 > local > 向上箭头标志commit changes.

    方法2. 菜单栏 > vcs > commit changes

    http://blog.csdn.net/pipisorry/article/details/39897949

    将代码push到github远程仓库中

    首先在pycharm中设置远程github账户密码

    file > settings > version control > github中设置github账户和密码
    1. 直接在源代码中Pushing your source code

    在某个py文件中 > Alt+`  > VCS operations pop-up window > 点击Push


    选择要push的project, 然后在弹出的窗口中输入github账户名和密码(如果在上一步设置过就应该不用输入了)

    亲测成功,登录github查看文件,文件都更新了。ps:本地文件原来在a目录并提交到github上,后来本地移动到b目录后,再提交到远程,github上的文件也会移动到b中,很好用!

    2. push当前pycharm控制的某个git目录所有修改到远程

    选中某个存在git控制的目录,点击菜单栏 > vcs > git > push

    3. 在changes窗口中,将修改commit到本地repository并push到远程仓库

    changes窗口 > 选中要提交修改的目录 >  vcs向上绿色箭头(commit) > 选择author填写commit message > commit下拉框选择commit and push, 这时会将选择的目录中的修改准备提交(注意不是整个项目所有改动过的文件)

    Note:

    1. 如果pycharm控制的工作目录对应的远程repostitory是py_workspace,并且其中包含的某子目录存在git目录,则此子目录不会同步到远程py_workspace仓库中,在github中看到的也只是灰色的子目录

    2. 上面存在git目录的某子目录对应的修改会push到其git目录对应的远程repository中,而不会提交到当前的父目录对应的repository中

    3. 从上可知,pycharm中push到的远程与git账户密码无关,而与目录中git设置的远程repository有关

    comit完成后,开始push要选择合并分支

    push操作可以和comit一起点,如果你只点了commit(或者push一开始失败,要再试一次),可以在progect显示中选中那个目录,再选择菜单栏 > VCS > git > push同伴可以到下面这个页面

    选择其中一个分支再点击push,这样代码就被push到远程了

    push冲突的解决

    (冲突:本地文件与远程文件相同位置的地方不同【同样的地方,它识别不出来应该用哪个】)

    这时会出现下面选择保留哪个文件或者手动合并两个存在差异的文件

    选择merge,如果存在冲突,push失败,会直接弹出框框(或者可以在下面的Event log失败提示中单击view them)

    如果push时你只要你自己的(本地的上传上去覆盖远程的),就选择Accept Yours

    如果你要保留远程的代码不修改,并且要远程的代码覆盖本地代码,就选择Accept Theirs,这时可买通过version control窗口(或者点击Event log中的提示)看到本地文件的变化

    如果你想看看不同,然后手动修改冲突就选择Merge

    Merger操作解决冲突

    点击merge就可以看到本地文件和远程的不同,通过图中如85行左右边的》符号修改可以通过解决冲突

    或者也可以这样操作:

    选择:菜单栏 > VCS > Git > Branches > 选择当前分支

    合并:菜单栏 > VCS > Git > Merge changes > 选择要和当前分支合并的分支

    http://blog.csdn.net/pipisorry/article/details/39897949

    将github远程仓库中的代码同步到本地

    从repository中获得最新的信息的3种方法

    • Press Ctrl+T
    • Click on the main toolbar
    • Choose VCS > Update Project...

    Note:

    1. 就是将github上的项目update到本地中(可以是不同电脑)。

    2. 表示没有在B电脑上输入github用户和密码就能进行这个操作,可能是pycharm登录的账户名相同吧??如果两个人使用同一个pycharm账户会怎样?

    Note:如果pycharm控制的工作目录还有子目录存在git目录,则此子目录也会被更新成远程的,被更新的子目录是根据子目录中的git而不是父目录中的git,即使子目录对应的git是别人github上的项目。

     [PyCharm Tutorials]

    只是pull某个目录(某个.git管理下的)的远程代码到本地

    在project中选择一个文件夹,如project项目中的labsite是某个git仓库对应的目录,选中

    然而右键 > Git > Repository > pull或者菜单栏VCS > Git > pull,就可以将对应远程仓库中的数据pull到本地中

    pull冲突的解决

    (冲突:本地commit或者文件与远程commit或者文件相同位置的地方不同【同样的地方,它识别不出来应该用哪个】)

    pull失败在EventLog中会有提示:

    23:23:27 Git Pull Failed
             Your local changes would be overwritten by merge.
             Commit, stash or revert them to proceed. View them

    这时点击view them就会出现很多存在冲突的文件

    1. 如果可以点开文件查看,点开某个文件,会显示如下远程文件(左)和本地文件(右your version)的对比差别

    如果你想手动取舍和合并两个版本,可以通过如上图101行左边的》符号修改

    如果你只想用本地的版本,就不做任何改动,不管就是了,下次push的时候解决冲突把远程的修改成本地的就可以

    如果你想用远程的版本替换本地的,可以选中存在冲突的文件,点击上方的revert就可以了

    2. 如果是因为本地commit的repository中的内容与远程冲突(e.g.本地文件已删除,但是本地repository上的文件未删除,并且与远程存在冲突),这时要先commit删除修改到本地repositoty中,再pull远程文件。

    在pycharm上打开github上的项目

    pycharm > 所有project空白界面上 > 右键 > open on github就可以直接在浏览器中打开github上对应的项目了

  • 相关阅读:
    机器学习-数据可视化神器matplotlib学习之路(四)
    [AspNetCore]CookieAuthentication禁用自动跳转到登录页
    [AspNetCore3.1] 使用Serilog记录日志
    [排序算法二]选择排序
    [排序算法一]冒泡排序
    Ocelot 网关 和 consul 服务发现
    AspNetCore3.0 和 JWT
    在AspNetCore3.0中使用Autofac
    【ElasticSearch+NetCore 第二篇】Nest封装
    【ElasticSearch+NetCore 第一篇】在Windows上安装部署ElasticSearch和ElasticSearch-head
  • 原文地址:https://www.cnblogs.com/xiongli/p/5782260.html
Copyright © 2011-2022 走看看