4 résultats taggé git

Oh Shit, Git!?!

Oh shit, I did something terribly wrong, please tell me git has a magic time machine!?!

git reflog
# you will see a list of every thing you've
# done in git, across all branches!
# each one has an index HEAD@{index}
# find the one before you broke everything
git reset HEAD@{index}
# magic time machine

Oh shit, I committed and immediately realized I need to make one small change!

# make your change
git add . # or add individual files
git commit --amend --no-edit
# now your last commit contains that change!
# WARNING: never amend public commits

Oh shit, I need to change the message on my last commit!

git commit --amend
# follow prompts to change the commit message

Oh shit, I accidentally committed something to master that should have been on a brand new branch!

# create a new branch from the current state of master
git branch some-new-branch-name
# remove the last commit from the master branch
git reset HEAD~ --hard
git checkout some-new-branch-name
# your commit lives in this branch now :)

Oh shit, I accidentally committed to the wrong branch!

# undo the last commit, but leave the changes available
git reset HEAD~ --soft
git stash
# move to the correct branch
git checkout name-of-the-correct-branch
git stash pop
git add . # or add individual files
git commit -m "your message here";
# now your changes are on the correct branch

Oh shit, I tried to run a diff but nothing happened?!

git diff --staged

Oh shit, I need to undo a commit from like 5 commits ago!

# find the commit you need to undo
git log
# use the arrow keys to scroll up and down in history
# once you've found your commit, save the hash
git revert [saved hash]
# git will create a new commit that undoes that commit
# follow prompts to edit the commit message
# or just save and commit

Oh shit, I need to undo my changes to a file!

# find a hash for a commit before the file was changed
git log
# use the arrow keys to scroll up and down in history
# once you've found your commit, save the hash
git checkout [saved hash] -- path/to/file
# the old version of the file will be in your index
git commit -m "Wow, you don't have to copy-paste to undo"

Fuck this noise, I give up.

# get the lastest state of origin
git fetch origin
git checkout master
git reset --hard origin/master
# delete untracked files and directories
git clean -d --force
# repeat checkout/reset/clean for each borked branch

How do I force "git pull" to overwrite local files?

# downloads the latest from remote without trying to merge or rebase anything
git fetch --all
# resets the master branch to what you just fetched
git branch backup-master
# changes all the files in your working tree to match the files
git reset --hard origin/master

Creating git repo on NTFS in Linux – Sub Zero Days

As a workaround, I simply made a symbolic link .git from the repo directory in Partition #3 to some directory in Partition #1, where my home directory resides.

How to make composer NOT create a .git directory for a package

If a package is seen as a git submodule, you haven't excluded the vendor folder from being committed to your own repository. It is recommended to add the vendor folder to .gitignore, and not commit these files, only commit composer.lock (and composer.json of course).

Apart from that, running composer install --prefer-dist should do the job. Note that Composer seems to not change the download method used first if you change your mind later. If Composer detects a cloned repo, it is faster to just update that instead of downloading a ZIP and unpacking it. If you want to change that, delete the whole vendor folder and run composer update --prefer-dist.