Herramientas de usuario

Herramientas del sitio


wiki2:gitcommands

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Ambos lados, revisión anterior Revisión previa
Próxima revisión
Revisión previa
wiki2:gitcommands [2017/09/28 11:07]
alfred [Moving]
wiki2:gitcommands [2020/06/16 12:26] (actual)
Línea 50: Línea 50:
  
  
 +==== View the graph ====
 +<​code>​
 +git log --graph --oneline --abbrev-commit
 +</​code>​
 ===== Files and folders ===== ===== Files and folders =====
 ==== Remove ==== ==== Remove ====
Línea 78: Línea 82:
 </​code>​ </​code>​
  
 +==== Undo last commit ====
 +<​code>​
 + git reset HEAD~ 
 +</​code>​
 +
 +==== Unstage changes ====
 +<​code>​
 +git rm --cached -r -- .
 +</​code>​
 +
 +===== Reset =====
 +==== Reset a full repo ====
 +<​code>​
 +git reset --hard HEAD
 +git clean -f -d
 +</​code>​
 +
 +==== Reset a single file ====
 +<​code>​
 +git checkout filename
 +</​code>​
 +
 +==== Reset a file with the same name as a branch ====
 +
 +<​code>​
 +git checkout -- filename
 +</​code>​
 +
 +==== Remove not tracket files ====
 +<​code>​
 +git clean -f -d 
 +</​code>​
 ===== Branches ===== ===== Branches =====
   * Create new branch: ''​git checkout -b [name_of_your_new_branch]''​   * Create new branch: ''​git checkout -b [name_of_your_new_branch]''​
Línea 91: Línea 127:
 </​code>​ </​code>​
  
-==== Eliminar branch ​local ====+==== Eliminar branch ==== 
 +=== Local ===
  
 <​code>​ <​code>​
 git branch -D no_queues git branch -D no_queues
 +</​code>​
 +
 +=== Remota ===
 +
 +<​code>​
 +git push origin --delete test
 </​code>​ </​code>​
  
Línea 123: Línea 166:
  
 Upload tags to the remote: ''​git push origin --tags ''​ Upload tags to the remote: ''​git push origin --tags ''​
 +
 +Remove a tag:
 +<​code>​
 +git push --delete origin <​tagname>​
 +</​code>​
 ===== Push over a non-bare repo ===== ===== Push over a non-bare repo =====
 You need to set denyCurrentBranch You need to set denyCurrentBranch
Línea 141: Línea 189:
 git reset --hard git reset --hard
 </​code>​ </​code>​
 +
 +===== Submodules =====
 +Create a submodule linked directly to the theme’s GitHub repository in order to receive updates:
 +<​code>​
 +$ git submodule add https://​github.com/​tomanistor/​osprey.git themes/​osprey
 +$ git submodule update --init --recursive --remote
 +</​code>​
 +
 +To update a downloaded repo with submodules:
 +<​code>​
 +$ git submodule init
 +$ git submodule update
 +</​code>​
 +===== Merges =====
 +
 +You should always keep in mind that you can return to the state before you started the merge at any time. This should give you the confidence that you can't break anything. On the command line, a simple ''​git merge --abort''​ will do this for you.
 +
 +In case you've made a mistake while resolving a conflict and realize this only after completing the merge, you can still easily undo it: just roll back to the commit before the merge happened with ''​git reset --hard ''​ and start over again.
 +
 +
 +===== Bundle =====
 +
 +Create a bundle file:
 +<​code>​
 +git bundle create your_name.bundle --all
 +</​code>​
 +Use it:
 +<​code>​
 +git clone <​path_to_bundle_file>​
 +</​code>​
 +===== Fixing =====
 +==== A detached head ====
 +
 +https://​stackoverflow.com/​a/​14757539
 +
 +If you type ''​git reflog'',​ it will show you the history of what revisions ''​HEAD''​ pointed to. Your detached head should be in there. Once you find it, do ''​git checkout -b my-new-branch abc123''​or ''​git branch my-new-branch abc123''​ (where ''​abc123''​ is the SHA-1 of the detached HEAD) to create a new branch that points to your detached head. Now you can merge that branch at your leisure.
 +
 +Generally, if you check out a branch after working on a detached head, Git should tell you the commit from the detached head you had been on, so you can recover it if you need. I've never used SourceTree, so I don't know if it relays that message. But if it did display that message, then you should be able to use that to find the commit, and again use ''​git checkout -b''​ or ''​git branch''​ to create a branch from that commit.
 ===== Extra ===== ===== Extra =====
 ==== Defining message editor ==== ==== Defining message editor ====
Línea 147: Línea 233:
 </​code>​ </​code>​
  
 +==== Use meld for UI for merging ====
 +
 +To use it for the current repo:
 +<​code>​
 +$ git mergetool -t meld
 +</​code>​
 +To configure git to remember which merge tool you want, type git config –global merge.tool [tool]. For meld use:
 +<​code>​
 +$ git config --global merge.tool meld
 +</​code>​
 ==== Several remotes ==== ==== Several remotes ====
  
Línea 162: Línea 258:
 </​code>​ </​code>​
  
 +Other easier:
 +<​code>​
 +git remote add gitea https://​git.alfredgg.dev/​gtd/​docker-without-pants.git
 +git push gitea
 +</​code>​
 ==== Use git from another folder ==== ==== Use git from another folder ====
 <​code>​ <​code>​
Línea 171: Línea 272:
 <​code>​ <​code>​
 git config --global credential.helper 'cache --timeout 86400' git config --global credential.helper 'cache --timeout 86400'
 +</​code>​
 +
 +<​code>​
 +git config credential.helper store
 +</​code>​
 +==== Gitlab beginning ====
 +
 +Git global setup
 +<​code>​
 +git config --global user.name "​user1"​
 +git config --global user.email "​user1@test.com"​
 +</​code>​
 +Create a new repository
 +<​code>​
 +git clone http://​127.0.0.1/​user1/​test.git
 +cd test
 +touch README.md
 +git add README.md
 +git commit -m "add README"​
 +git push -u origin master
 +</​code>​
 +Existing folder
 +<​code>​
 +cd existing_folder
 +git init
 +git remote add origin http://​127.0.0.1/​user1/​test.git
 +git add .
 +git commit -m "​Initial commit"​
 +git push -u origin master
 +</​code>​
 +Existing Git repository
 +<​code>​
 +cd existing_repo
 +git remote rename origin old-origin
 +git remote add origin http://​127.0.0.1/​user1/​test.git
 +git push -u origin --all
 +git push -u origin --tags
 </​code>​ </​code>​
wiki2/gitcommands.1506596846.txt.gz · Última modificación: 2020/05/09 09:25 (editor externo)