pycharm版本控制

轉載至:http://blog.csdn.net/pipisorry/article/details/39897949html

[不瞭解git版本控制的能夠閱讀這篇 -  Git版本控制教程 - Git本地倉庫]

開啓版本控制node

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

  • 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.github

Note:web

1. 若是Python workspace已經在Git版本控制下了,點擊version control就會看到Directory下有提示unregistered roots:project_name,點擊這個project,再點擊+號就添加到版本控制中了。windows

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.app

  • 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窗口中添加:ide

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上對應的項目了

相關文章
相關標籤/搜索