Git http://drupal8.ovh/en/tags/git en GIT , Remove all old changes and make Current as initial http://drupal8.ovh/en/tutoriels/231/git-remove-all-old-changes-and-make-current-as-initial <span class="field field--name-title field--type-string field--label-hidden">GIT , Remove all old changes and make Current as initial</span> <div class="clearfix text-formatted field field--name-field-question field--type-text-long field--label-above"> <div class="field__label">Question</div> <div class="field__item"><p>How to remove all git repository history and set the current state as initial commit ?</p> </div> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Sun, 09/18/2016 - 11:10</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>This is the <strong>brute-force </strong>method. It also removes the configuration of the repository.</p> <p>Step 1: remove all history<br /><code>rm -rf .git</code></p> <p>Step 2: reconstruct the Git repository with current content<br /><code>git init<br /> git add .<br /> git commit -m "Initial Commit"</code></p> <p>Step 3: push to Git.<br /><code>git remote add origin &lt;git-uri&gt;<br /> git push -u --force origin master</code></p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/git" hreflang="en">Git</a></li> <li><a href="/en/tags/server" hreflang="en">Server</a></li> </ul> </div> <div class="field field--name-field-related-contents field--type-entity-reference field--label-hidden field__items"> <div class="field__item"><a href="/en/tutoriels/11/helpful-git-commands" hreflang="en">Helpful git commands</a></div> <div class="field__item"><a href="/en/tutoriels/114/make-correction-on-a-git" hreflang="en">Make Correction on a git</a></div> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=231&amp;2=comment&amp;3=comment" token="e6e81460"></drupal-render-placeholder> </section> Sun, 18 Sep 2016 09:10:54 +0000 editor 231 at http://drupal8.ovh Git - Ignore Files, Directories, Permissions http://drupal8.ovh/en/tutoriels/157/git-ignore-files-directories-permissions <span class="field field--name-title field--type-string field--label-hidden">Git - Ignore Files, Directories, Permissions</span> <div class="clearfix text-formatted field field--name-field-question field--type-text-long field--label-above"> <div class="field__label">Question</div> <div class="field__item"><p>What are the methodes to ignore files, directories/folders, file permissions ... of the git repository ?</p> </div> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Fri, 06/10/2016 - 09:57</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><h2>1 Ignore files And Folders using <strong><code>.gitignore</code></strong> Files (Include and/or Exclude)</h2> <p>Create the gitignore file at the top of your repository,i f it's not already exist<br /> To Exclude A file/folder just add file path or the directory path like:</p> <p><code>.htaccess<br /> README.txt<br /> backup<br /> htdocs/temp<br /> htdocs/sites/*/files<br /> htdocs/sites/*/private</code></p> <p> To re include a file / Folder already excluden before</p> <p><code>!backup/file_to_include.txt<br /> !htdocs/sites/all<br /> !htdocs/sites/*/files/folder_to_include</code></p> <h2>2. Ignore File mode / file permissions (chmod/chown) using git config</h2> <p>(<strong>Examples are not tested</strong>)</p> <p><code>git config core.fileMode false #For a specific repo<br /> git config --global core.filemode false #For all of your repos</code></p> <p>If this does not work you are probably using a newer version of git so try the <code>--add</code> option.<br /><code>git config --add --global core.filemode false </code></p> <p>If you run it without the --global option and your working directory is not a repo, you'll get<br /><code>error: could not lock config file .git/config: No such file or directory </code></p> <p>If this does not work, you can also do it manually:<br /> 1. Go to the <code>.git</code> Folder of your repository (<code>cd path_to/your_project_repo/.git</code>)<br /> 2. Edit the <code>config</code> File (<code>vim config</code>)<br /> 3. Change <code>filemode = true </code>to<code> filemode = false </code>And Save<br /><code>[core]<br />         repositoryformatversion = 0<br />         filemode = false</code><br /> 4. Reinit the git (<code>git init</code>)</p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/shell" hreflang="en">Shell</a></li> <li><a href="/en/tags/server" hreflang="en">Server</a></li> <li><a href="/en/tags/git" hreflang="en">Git</a></li> </ul> </div> <div class="field field--name-field-related-contents field--type-entity-reference field--label-hidden field__items"> <div class="field__item"><a href="/en/tutoriels/11/helpful-git-commands" hreflang="en">Helpful git commands</a></div> <div class="field__item"><a href="/en/tutoriels/114/make-correction-on-a-git" hreflang="en">Make Correction on a git</a></div> <div class="field__item"><a href="/en/tutoriels/118/create-and-apply-patches-using-git-diff-and-apply" hreflang="en">Create and Apply Patches using GIT DIFF and APPLY</a></div> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=157&amp;2=comment&amp;3=comment" token="a1fe7a7b"></drupal-render-placeholder> </section> Fri, 10 Jun 2016 07:57:56 +0000 editor 157 at http://drupal8.ovh http://drupal8.ovh/en/tutoriels/157/git-ignore-files-directories-permissions#comments Create and Apply Patches using GIT DIFF and APPLY http://drupal8.ovh/en/tutoriels/118/create-and-apply-patches-using-git-diff-and-apply <span class="field field--name-title field--type-string field--label-hidden">Create and Apply Patches using GIT DIFF and APPLY</span> <div class="clearfix text-formatted field field--name-field-question field--type-text-long field--label-above"> <div class="field__label">Question</div> <div class="field__item"><p>How to Create and Apply Patches in GIT using diff and apply Command</p> </div> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Tue, 02/16/2016 - 10:46</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Create Patch:<br /><code>git diff PATH/TO/SOURCE.php &gt; PATH/SAVE_patch.diff</code></p> <p>Apply patch<br /><code>git apply PATH/SAVE_patch.diff</code></p> <p>More Info : http://www.thegeekstuff.com/2014/03/git-patch-create-and-apply/</p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/shell" hreflang="en">Shell</a></li> <li><a href="/en/tags/git" hreflang="en">Git</a></li> </ul> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=118&amp;2=comment&amp;3=comment" token="be150169"></drupal-render-placeholder> </section> Tue, 16 Feb 2016 09:46:00 +0000 editor 118 at http://drupal8.ovh http://drupal8.ovh/en/tutoriels/118/create-and-apply-patches-using-git-diff-and-apply#comments Make Correction on a git http://drupal8.ovh/en/tutoriels/114/make-correction-on-a-git <span class="field field--name-title field--type-string field--label-hidden">Make Correction on a git</span> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Wed, 02/03/2016 - 12:05</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><h3>1. Remove Files</h3> <p>Step 1. Switch to your branch<br /> Strp 2. Remove files using -rm command<br /> Ex :  <code>git rm -r sites/all/modules/stage_file_proxy</code><br /> Step 3. Add this file to the .gitignore</p> <h3>2. Resolve a conflict</h3> <p>#Quickly Resolve conflict<br /><code>grep -lr '&lt;&lt;&lt;&lt;&lt;&lt;&lt;' . #Find conflicted files<br /> git checkout --ours PATH/FILE #use my file<br /> git checkout --theirs PATH/FILE #use the remotr/other file</code></p> <p><code>grep -lr '&lt;&lt;&lt;&lt;&lt;&lt;&lt;' . | xargs git checkout --ours<br /> grep -lr '&lt;&lt;&lt;&lt;&lt;&lt;&lt;' . | xargs git checkout --theirs</code></p> <p>Get a file from Head<br /><code>git checkout HEAD PATH/TO/FILE<br /> git checkout PATH/TO/FILE</code></p> <h3>3.Other Solutions</h3> <p>1. Ignore all local changes and get from frmote master</p> <p><code>git checkout path/to/file.ext</code></p> <p>2.</p> <p>4. Find the most recent commits and Files<br /> To see last commits<br /> git log<br /> To see the different<br /><code>​git show THE_COMMIT_ID</code><br /> To get the modified files list<br /><code>​git show --name-only THE_COMMIT_ID</code></p> <p>5. Undo <code>git add</code> (to remove from 'add', to correct faultly added files)<br /> git reset THE_FILE_NAME</p> <p>6. Revert Last commit and pull<br /> #Revert last Commit(s)<br /><code>git reset HEAD^ ;Last commit</code><br /><code>git reset HEAD^N ;Last N commit (N = int)<br /> git reset HEAD^^  =  git reset HEAD^2, git reset HEAD^^^ = git reset HEAD^3</code></p> <p>#Revert last pull<br /><code>git reset HEAD@{1}</code></p> <p>#Git Remove all local changes and pull<br /><code>git reset --hard origin/master<br /> git pull origin master</code></p> <p>#Git Remove all local changes of a file and get from remote<br /><code>git checkout path/to/file.txt</code><br />  </p> <p>7. Delete a branch /!\ CAUTION<br /> #Local<br /><code>git branch -d the_local_branch</code><br /> #Remote<br /><code>git push origin :the_remote_branch</code></p> <h3>8.Rename a branch</h3> <p>Rename Any branch<br /><code>git branch -m &lt;oldname&gt; &lt;newname&gt; </code></p> <p>Rename the current branch<br /><code>git branch -m &lt;newname&gt;</code></p> <p>To reset Found and Reset git commands<br /><code>git reflog #To get the list<br /> git reset HEAD@{1} #To reset to this version<br /> git reset aabbccdd #To reset to this version</code><br />  </p> <p>To save changes:<br /><code>git stash #To save changes<br /> git stash pop #To get saved changes</code></p> <p>To get selected commits, or isolate some commits:<br /><code>#1.Create new branche<br /> git cherry-pick &lt;the_commit_number Ex: aa4e310086272a7892143dabcdac26b163625dbf&gt;<br /> #Commit and push the new branch</code></p> <p>Force a PULL<br /><code>git push -f origin yourbranch</code></p> <p>Move from A source branch to another source Branche<br /> (For example, When you must start [create new branche] from <code><strong>maser </strong></code>but you are started from <strong><code>develop</code></strong>)<br /> Methode 1:<br /> 1. Go to the badly started branche (<code>git checkout NEW_BAD</code>)<br /> 2 Reset last commits (<code>git reser HEAD^</code>)<br /> 3 Save changes using stash (<code>git stash</code>)<br /> 4 Go to the MASTER branche (<code>git checkout MASTER</code>)<br /> 5 Create a new branche from MASTER (<code>git checkout -b  NEW_FROM_MASTER</code>)<br /> 6 Re load saved changes from stash (<code>git stash pop</code>)<br /> 7 Add, Commit and Push your changes (<code>git commit -am 'comment'</code>)<br /> Methode 2.<br /> 1. Go to the badly started branche (<code>git checkout NEW_BAD</code>)<br /> 2  Get the commit number/numbers like <code>aa4e310086272a7892143dabcdac26b163625dbf</code> (<code>git log</code>)4 Go to the MASTER branche (<code>git checkout MASTER</code>)<br /> 3 Go to the MASTER branche (<code>git checkout MASTER</code>)<br /> 5 Create a new branche from MASTER (<code>git checkout -b  NEW_FROM_MASTER</code>)<br /> 6 Load  your commits using <code>cherry-pick </code>(<code>git cherry-pick &lt;the_commit_number Ex: aa4e310086272a7892143dabcdac26b163625dbf&gt;</code>)<br /> 7 Add, Commit and Push your changes (<code>git commit -am 'comment'</code>)</p> <p> </p> <p>Resolve a git merge conflict in from remote/origin<br /><code>git pull -X theirs</code></p> <p>.</p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/shell" hreflang="en">Shell</a></li> <li><a href="/en/tags/git" hreflang="en">Git</a></li> <li><a href="/en/tags/server" hreflang="en">Server</a></li> </ul> </div> <div class="field field--name-field-related-contents field--type-entity-reference field--label-hidden field__items"> <div class="field__item"><a href="/en/tutoriels/112/git-include-and-exclude-by-gitignore" hreflang="en">Git - Include and Exclude by .gitignore</a></div> <div class="field__item"><a href="/en/tutoriels/231/git-remove-all-old-changes-and-make-current-as-initial" hreflang="en">GIT , Remove all old changes and make Current as initial</a></div> <div class="field__item"><a href="/en/tutoriels/11/helpful-git-commands" hreflang="en">Helpful git commands</a></div> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=114&amp;2=comment&amp;3=comment" token="5efb2ca5"></drupal-render-placeholder> </section> Wed, 03 Feb 2016 11:05:49 +0000 editor 114 at http://drupal8.ovh http://drupal8.ovh/en/tutoriels/114/make-correction-on-a-git#comments Git - Include and Exclude by .gitignore http://drupal8.ovh/en/tutoriels/112/git-include-and-exclude-by-gitignore <span class="field field--name-title field--type-string field--label-hidden">Git - Include and Exclude by .gitignore</span> <div class="clearfix text-formatted field field--name-field-question field--type-text-long field--label-above"> <div class="field__label">Question</div> <div class="field__item"><p>How to Include and Exclude files using .gitignore file ?</p> <p>Why gitignore not working ?</p> </div> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Thu, 01/28/2016 - 10:25</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><h2>Ignore files and folders using .gitignore</h2> <p>Example 1. Ignore (<strong>Exclude</strong>) a simple file or a folder<br /><code>sites/default/settings.php<br /> sites/*/files</code></p> <p>Example 2. <strong>Include </strong>a file / folder<br /><code>!sites/default/testfile.php<br /> !sites/*/testfolder</code></p> <p>Example 2. <strong>Include </strong>a file located in a <strong>Excluded </strong>folder<br /> Step 1. <strong>Include </strong>the 'Excluded' folder<br /><code>!sites/*/files</code><br /> Step 2. <strong>Exclude </strong>All files and folders in this folder<br /><code>sites/*/files/*</code><br /> Step 3. <strong>Re Include</strong> the specific file or folder<br /><code>!sites/default/files/my_included_file.pdf</code></p> <h2>Git Cache : gitignore not working</h2> <p>If files are already cached, .gitignore may not working</p> <p>Solutions.<br /><em><strong>CAUTION !!! Do not forget to commit your changes before all this operations</strong></em></p> <h3>1. Rebuild all cache</h3> <p><code>git rm -r --cached .<br /> git add .<br /> git commit -m "clear all cache to fix file tracking"</code></p> <h3>2. Remove cache of a folder already added to the git</h3> <p><code>git rm -r --cached thefile.txt thefolder</code></p> <h3>3 Remove cache of a file already added to the git</h3> <p><code> git rm --cached sites/default/settings.php</code></p> <p> </p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/git" hreflang="en">Git</a></li> <li><a href="/en/tags/server" hreflang="en">Server</a></li> <li><a href="/en/tags/shell" hreflang="en">Shell</a></li> </ul> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=112&amp;2=comment&amp;3=comment" token="2e8c3a43"></drupal-render-placeholder> </section> Thu, 28 Jan 2016 09:25:17 +0000 editor 112 at http://drupal8.ovh http://drupal8.ovh/en/tutoriels/112/git-include-and-exclude-by-gitignore#comments Git - Create new branche, push and merge http://drupal8.ovh/en/tutoriels/96/git-create-new-branche-push-and-merge <span class="field field--name-title field--type-string field--label-hidden">Git - Create new branche, push and merge</span> <div class="clearfix text-formatted field field--name-field-question field--type-text-long field--label-above"> <div class="field__label">Question</div> <div class="field__item"><p>How to create new branche, push and merge to make a correction ... ?</p> </div> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Wed, 01/06/2016 - 16:13</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>git checkout -b // TO TEST</p> <p> git branch &lt;branche&gt;  // TO TEST</p> <p><strong>Create new branche from current branche</strong><br /> git checkout &lt;branche&gt;  <br /> OR<br /> git checkout -b &lt;branche&gt; (Example : function/VERSION_ID/BUG_TICKET_ID ((feature/1.6/123456))<br /> Ex: <code>git checkout -b release/1.0.2/123</code><br /><strong>Create new branche from ANOTHER branche (Ex: version/master)</strong><br /> git checkout -b &lt;new_branche&gt; &lt;source&gt;<br /> Ex: <code>git checkout -b release/1.0.2/123 origin/version/master</code></p> <p> </p> <p>git add --all</p> <p>git commit -m "The comment, Message, Correction ..."</p> <p>git push origin the/new/brancge/BUGID<br />  </p> <p><strong>Create a new branch from remote branch other than HEAD (Ex origin/develop)</strong><br /><code>git checkout -b develop origin/develop</code></p> <p><code>OR</code></p> <p><code>git checkout release-v1<br /> git pull origin release-v1</code></p> <p> </p> <h2>Git merge example</h2> <p><code>git checkout develop<br /> git pull origin develop<br /> git checkout master<br /> git pull origin master<br /> git merge develop<br /> git push origin master</code></p> <h3>Put into production server</h3> <p><code>git checkout master<br /> git pull origin master</code></p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/git" hreflang="en">Git</a></li> <li><a href="/en/tags/code" hreflang="en">Code</a></li> </ul> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=96&amp;2=comment&amp;3=comment" token="80f1cab3"></drupal-render-placeholder> </section> Wed, 06 Jan 2016 15:13:13 +0000 editor 96 at http://drupal8.ovh http://drupal8.ovh/en/tutoriels/96/git-create-new-branche-push-and-merge#comments Helpful git commands http://drupal8.ovh/en/tutoriels/11/helpful-git-commands <span class="field field--name-title field--type-string field--label-hidden">Helpful git commands</span> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Mon, 11/16/2015 - 16:30</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>#Download / Get git repository<br /><code>git clone http://url-of-your-git/project.git</code></p> <p>#Show remore url<br /><code>git remote -v</code></p> <p> </p> <p>#Quickly Resolve conflict<br /><code>grep -lr '&lt;&lt;&lt;&lt;&lt;&lt;&lt;' .<br /> git checkout --ours PATH/FILE<br /> git checkout --theirs PATH/FILE</code></p> <p> </p> <p><code>grep -lr '&lt;&lt;&lt;&lt;&lt;&lt;&lt;' . | xargs git checkout --ours<br /> grep -lr '&lt;&lt;&lt;&lt;&lt;&lt;&lt;' . | xargs git checkout --theirs</code></p> <p> #Remove all local changes<br /><code>git reset --hard<br /> git pull</code></p> <p>#Switch / Change / Move HEAD branch<br /><code>git remote set-head origin new_head_branch</code></p> <p>Saving / Caching  Git password<br /><span><code>git config --global credential.helper cache<br /> git config --global credential.helper 'cache --timeout=28800' #28800=8 hours</code></span></p> <p> </p> <p>#Confugure Name/ EMail<br /><code>git config --global user.name "Your Name"<br /> git config --global user.email you@email.com</code></p> <p>#Delete a branch /!\ CAUTION<br /> #Local<br /><code>git branch -d the_local_branch</code><br /> #Remote<br /><code>git push origin :the_remote_branch</code></p> <p> </p> <p><strong>Show Different:</strong><br /> View finally comited files and the commit ID<br /><code>git log --name-status HEAD^..HEAD</code><br /> View A commit's Files<br /><code>git diff-tree --no-commit-id --name-only -r THE_COIMMIT_ID</code><br /> View the different<br /><code>git diff THE_COIMMIT_ID^!</code></p> <p><strong>Update local repository info</strong><br /><code>git fetch</code></p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/git" hreflang="en">Git</a></li> <li><a href="/en/tags/code" hreflang="en">Code</a></li> </ul> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=11&amp;2=comment&amp;3=comment" token="04b3e5a0"></drupal-render-placeholder> </section> Mon, 16 Nov 2015 15:30:20 +0000 editor 11 at http://drupal8.ovh http://drupal8.ovh/en/tutoriels/11/helpful-git-commands#comments