詳細検索

It's OPS, but I tried using Git ~ Part 2

Avatar
by komi
4 min read

It's OPS, but I tried using Git ~ Part 2
Translated from 日本語 • View original

Hello. This is Komiya. This is a continuation of the previous article. This time I'm going to write about git merges and tags and conflicts. Well, please watch warmly as it is when beginners get used to it. I don't talk about git-flow or branch models.

Break branch with git branch

Check where you are

$ git branch -a
  add_custom_repository
* master

Make sure there is no one that just added.

$ git status
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   .gitignore
#
no changes added to commit (use "git add" and/or "git commit -a")   

*If there is a guy who just added, you need to commit or stash.

Cut and move a new branch
$ git checkout -b add_xxxx-options
$ git branch -a

Check for * in the new location git-checkout(1) if you just want to move it instead of creating a branch (don't add -b)

$ git checkout <branch-name>
$ git branch -a
Fix
$ git add <filename>
$ git commit -m 'comment'

When pushing,

$ git push origin <branch-name1>:<branch-name1>

In this way, you don't have to write arguments after .git/config is registered, as shown below

[branch "<branch-name1>"]
        remote = origin
        merge = refs/heads/<branch-name1>

However, if you don't add an argument, all local branches will be pushed, so be careful if you are not in a state where you can push

Once the correction is made, check it with a dry run with knife solo

About merging to master

Git - Branching and Merge Basics You can create a merge request on the gitlab GUI (which is called a pullik on github) Select the Merge Requests link and click +New Merge Request to decide which branch you want to merge from. If it doesn't look good, allow that merge request.

Or git marge. Just go to master (the branch you want to marge) and git marge <margeしたいブランチ名>and commit. If you are worried, you can cut a new branch for verification and try to marge there.

If a conflict occurs, we will respond by carefully looking at or searching for the above URL.

About ##### tag

A tag is like a label attached to a commit. It is used for versioning specific commits with specific tags.

Normally, you tag them immediately after committing

$ git tag

You can get a list of tags and tags.

$ git tag <tag-name>

If you hit it, you can add a new tag to the current HEAD.

As it is, it will be a tag that only makes sense locally, so to push the tag to the remote origin, do the following

$ git push origin <tag-name>

If you want to view the contents of the tag, you can check out

$ git checkout <tag-name>

However, this will result in an isolated HEAD state, so even if you update in this state, you cannot commit anywhere. If you want to leave this update, you can do it by adding -b, cutting a new branch and committing there. Tags are just pointers and cannot be updated, so it is better to go back to a branch somewhere with checkout and then update them.

How to identify ##### confrict in advance

git format-patch. You can't just use a pointer, but please see the link for details. How to find out if there is a conflict in git merge in advance - Qiita Looking at this, I identified the same conflicting areas and adjusted the locations to the same across branches, and the merge button appeared in the browser. I think it's easy to snap this. If you're unsure, check with 'git diff master ' or 'git checkout ' I think it would be a good idea to commit only a specific file to another branch.

Current History Ranking

It's a bonus. The use is different depending on the work environment, so the rankings are different.

@某社内鯖
# history | awk '{print $4}' | sort | uniq -c | sort -nr | head
   1598 git
    768 vi
    382 cat
    341 ls
    249 cd
    222 bundle
    189 aws
    139 knife
    116 ./ruby
     83 for
@某リモート鯖
$ history | awk '{print $2}' | sort | uniq -c | sort -nr | head
    185 kitchen
    183 vi
    119 git
     56 ssh
     47 cd
     38 w
     34 ls
     29 df
     24 for
     22 cat

If there is anything else, I would like to refer to the following. 19 Tips You Can Use When You Do It in Git - Qiita Know-How About git push.default - Qiita By the way, I thought the cheat sheet at the beginning of the Git Pocket Reference was the easiest to understand.

Well, it's short, but it's the end of the series, so thank you for reading. </margeしたいブランチ名>

Related Articles