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:\Git\bin\git.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上對應的項目了

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM